Scenes:
Using version 6.1 of Yolov5, it is possible to use the cpu version of pytorch for training, but change to gpu to train your own data set, and suddenly report this error after several training sessions.
Solution
After searching the Internet, there are roughly three methods:
1. Restart pycharm (tried to no avail)
2. Modify num_workers (somewhat useful)
This parameter is in the utils/datasets.py file, set num_workers=0 , as follows:
return loader(dataset,
batch_size=batch_size,
shuffle=shuffle and sampler is None,
num_workers=nw, #这里修改为0
sampler=sampler,
pin_memory=True,
collate_fn=LoadImagesAndLabels.collate_fn4 if quad else LoadImagesAndLabels.collate_fn), dataset
When I first tried this method, it worked, but then it didn’t work for no reason, and I didn’t know what it was useful for, and I felt that it was not good to modify it, so I gave up decisively and continued to search.
3. Increase the size of the page file and change the batch_size (solve the problem)
After clicking on the advanced system settings, click on the settings on the picture --> change , and follow the steps below step by step.
After clicking Change, remove the tick before automatically manage the paging file size of all drives , as shown in the figure below:
Finally, set the size of the virtual memory according to the available space of your D drive, and finally click OK. Then restarting the computer solved the problem. Changing the size of the D drive is mainly because my anaconda, the configured virtual environment and the corresponding python are all on the D drive. (If Python is installed on the C drive, increase the value of the virtual memory of the C drive.)
If the virtual memory of the D drive has been set before and the same error is reported, you can try to reduce your own batch_size. If it still doesn't work, you can only try to modify num_works.