深度学习训练过程报错:
Traceback (most recent call last):
File "D:\workspace\out-in-noise-lt\method\method2.py", line 280, in <module>
main_workers()
File "D:\workspace\out-in-noise-lt\method\method2.py", line 250, in main_workers
train2(epoch, labeled_loader, unlabeled_loader, model, criterion_ce, optimizer, scaler,
File "D:\workspace\out-in-noise-lt\method\method2.py", line 161, in train2
unlabeled_loader_iter = iter(unlabeled_loader)
^^^^^^^^^^^^^^^^^^^^^^
File "D:\env\anaconda3\envs\torch2.3\Lib\site-packages\torch\utils\data\dataloader.py", line 439, in __iter__
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "D:\env\anaconda3\envs\torch2.3\Lib\multiprocessing\spawn.py", line 122, in spawn_main
exitcode = _main(fd, parent_sentinel)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\env\anaconda3\envs\torch2.3\Lib\multiprocessing\spawn.py", line 132, in _main
self = reduction.pickle.load(from_parent)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
EOFError: Ran out of input
return self._get_iterator()
^^^^^^^^^^^^^^^^^^^^
File "D:\env\anaconda3\envs\torch2.3\Lib\site-packages\torch\utils\data\dataloader.py", line 387, in _get_iterator
return _MultiProcessingDataLoaderIter(self)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\env\anaconda3\envs\torch2.3\Lib\site-packages\torch\utils\data\dataloader.py", line 1040, in __init__
w.start()
File "D:\env\anaconda3\envs\torch2.3\Lib\multiprocessing\process.py", line 121, in start
self._popen = self._Popen(self)
^^^^^^^^^^^^^^^^^
File "D:\env\anaconda3\envs\torch2.3\Lib\multiprocessing\context.py", line 224, in _Popen
return _default_context.get_context().Process._Popen(process_obj)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\env\anaconda3\envs\torch2.3\Lib\multiprocessing\context.py", line 337, in _Popen
return Popen(process_obj)
^^^^^^^^^^^^^^^^^^
File "D:\env\anaconda3\envs\torch2.3\Lib\multiprocessing\popen_spawn_win32.py", line 95, in __init__
reduction.dump(process_obj, to_child)
File "D:\env\anaconda3\envs\torch2.3\Lib\multiprocessing\reduction.py", line 60, in dump
ForkingPickler(file, protocol).dump(obj)
AttributeError: Can't pickle local object 'SubPolicy.__init__.<locals>.<lambda>'
运行环境:
# Name Version Build Channel
pytorch 2.3.1 py3.12_cuda12.1_cudnn8_0 pytorch
数据量不是特别大,可以考虑使用单进程模式加载数据,避免序列化问题,可以设置Dataloader的num_workers=0