Pytorch Run Error: BrokenPipeError [How to Solve]

The problem occurs when doing machine learning training.

Reason for the error: The problem is due to multi-threading under windows, and is related to the DataLoader class. Just change the number of num_workers to 0. This is a bug in windows.

The error code can be referred to:

trainLoader=torch.utils.data.DataLoader(trainSet,batch_size=Bach_Size,shuffle=True,num_workers=2)
testLoader=torch.utils.data.DataLoader(testSet,batch_size=Bach_Size,shuffle=True,num_workers=2)

Set The number of num_ workers to 0

trainLoader=torch.utils.data.DataLoader(trainSet,batch_size=Bach_Size,shuffle=True,num_workers=0)
testLoader=torch.utils.data.DataLoader(testSet,batch_size=Bach_Size,shuffle=True,num_workers=0)

Read More: