BrokenPipeError: [Errno 32] Broken pipe解决方法

使用pytorch运行代码报错:

BrokenPipeError: [Errno 32] Broken pipe

解决方案:

令 torch.utils.data.DataLoader() 函数的 num_workers = 0

例如:

train_loader = torch.utils.data.DataLoader(
    SVHNDataset(train_path, train_label,
                transforms.Compose([
                    transforms.Resize((64, 128)),
                    transforms.RandomCrop((60, 120)),
                    transforms.ColorJitter(0.3, 0.3, 0.2),
                    transforms.RandomRotation(5),
                    transforms.ToTensor(),
                    transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])
    ])), 
    batch_size=40, 
    shuffle=True, 
    num_workers=0, # 在此处,把num_workers设为0
)

你可能感兴趣的:(BrokenPipeError: [Errno 32] Broken pipe解决方法)