pytorch报错RuntimeError: DataLoader worker (pid(s) 7872, 15356, 19144, 16296) exited unexpectedly

  • Post author:
  • Post category:其他


Traceback (most recent call last):
  File "D:/python/Dive into DL/pytorch/CH3/softmax.py", line 42, in <module>
    print(evaluate_accuracy(test_iter, net))
  File "D:/python/Dive into DL/pytorch/CH3/softmax.py", line 37, in evaluate_accuracy
    for X, y in data_iter:
  File "E:\environment\python\lib\site-packages\torch\utils\data\dataloader.py", line 804, in __next__
    idx, data = self._get_data()
  File "E:\environment\python\lib\site-packages\torch\utils\data\dataloader.py", line 771, in _get_data
    success, data = self._try_get_data()
  File "E:\environment\python\lib\site-packages\torch\utils\data\dataloader.py", line 737, in _try_get_data
    raise RuntimeError('DataLoader worker (pid(s) {}) exited unexpectedly'.format(pids_str))
RuntimeError: DataLoader worker (pid(s) 7872, 15356, 19144, 16296) exited unexpectedly

因为torch.utils.data.DataLoader中设置了num_works=4,也就是多线程读取。pytorch在Windows下的多线程读取好像有点问题,将num_works改为1问题即可解决。如果还是报错的话,可以试试将num_works这个参数去掉。



版权声明:本文为weiyongle1996原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。