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
)
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章