Using windows for YOLO8 training reports an error ForkingPickler(file, protocol).dump(obj) BrokenPipeError: [Errno 32] BrokenPipe

Using windows for YOLO8's custom data training reports an error ForkingPickler(file, protocol).dump(obj)BrokenPipeError: [Errno 32] Broken pipe

1. The problem occurs as follows:

2. The reason for the error:

This problem is caused by the multi-threading problem under windows, which is related to the DataLoader class. Change the number of num_workers to 0. It feels like this is a bug in windows.

3. Solutions:

In general, just change num_workers=1 in train.py to 0, as follows:

trainset = torchvision.datasets.CIFAR10(root='./data',train=True,
                                          download=True,transform=transform)
trainloader = torch.utils.data.DataLoader(trainset,batch_size=4,
                                            shuffle = True,num_workers=1) #改为0

But I searched for a long time and couldn't find where the num_workers of yolo8's train.py is. Finally, I found that the num_workers returned by the build_dataloader function in build.py can be changed, as follows:

def build_dataloader(cfg, batch, img_path, stride=32, rect=False, names=None, rank=-1, mode='train'):...

The specific location of the file is:

你安装的虚拟环境\Lib\site-packages\ultralytics\yolo\data\build.py

The pro-test is effective!

Guess you like

Origin blog.csdn.net/Jin1Yang/article/details/129236974