使用pytorch,遇到错误:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
Traceback (most recent call last): File "<string>", line 1, in <module> File "E:\ProgramData\Anaconda3\envs\pytorch\lib\multiprocessing\spawn.py", line 105, in spawn_main exitcode = _main(fd) File "E:\ProgramData\Anaconda3\envs\pytorch\lib\multiprocessing\spawn.py", line 114, in _main prepare(preparation_data) File "E:\ProgramData\Anaconda3\envs\pytorch\lib\multiprocessing\spawn.py", line 225, in prepare _fixup_main_from_path(data['init_main_from_path']) File "E:\ProgramData\Anaconda3\envs\pytorch\lib\multiprocessing\spawn.py", line 277, in _fixup_main_from_path run_name="__mp_main__") File "E:\ProgramData\Anaconda3\envs\pytorch\lib\runpy.py", line 263, in run_path pkg_name=pkg_name, script_name=fname) File "E:\ProgramData\Anaconda3\envs\pytorch\lib\runpy.py", line 96, in _run_module_code mod_name, mod_spec, pkg_name, script_name) File "E:\ProgramData\Anaconda3\envs\pytorch\lib\runpy.py", line 85, in _run_code exec(code, run_globals) File "E:\01 个人文档\荔枝面条\07 学习资料\07 代码\PycharmProject\pytorch\t.py", line 65, in <module> dataiter = iter(trainloader) File "E:\ProgramData\Anaconda3\envs\pytorch\lib\site-packages\torch\utils\data\dataloader.py", line 278, in __iter__ return _MultiProcessingDataLoaderIter(self) File "E:\ProgramData\Anaconda3\envs\pytorch\lib\site-packages\torch\utils\data\dataloader.py", line 682, in __init__ w.start() File "E:\ProgramData\Anaconda3\envs\pytorch\lib\multiprocessing\process.py", line 112, in start self._popen = self._Popen(self) File "E:\ProgramData\Anaconda3\envs\pytorch\lib\multiprocessing\context.py", line 223, in _Popen return _default_context.get_context().Process._Popen(process_obj) File "E:\ProgramData\Anaconda3\envs\pytorch\lib\multiprocessing\context.py", line 322, in _Popen return Popen(process_obj) File "E:\ProgramData\Anaconda3\envs\pytorch\lib\multiprocessing\popen_spawn_win32.py", line 46, in __init__ prep_data = spawn.get_preparation_data(process_obj._name) File "E:\ProgramData\Anaconda3\envs\pytorch\lib\multiprocessing\spawn.py", line 143, in get_preparation_data _check_not_importing_main() File "E:\ProgramData\Anaconda3\envs\pytorch\lib\multiprocessing\spawn.py", line 136, in _check_not_importing_main is not going to be frozen to produce an executable.''') RuntimeError: An attempt has been made to start a new process before the current process has finished its bootstrapping phase. This probably means that you are not using fork to start your child processes and you have forgotten to use the proper idiom in the main module: if __name__ == '__main__': freeze_support() ... The "freeze_support()" line can be omitted if the program is not going to be frozen to produce an executable. Traceback (most recent call last): File "E:/01 个人文档/荔枝面条/07 学习资料/07 代码/PycharmProject/pytorch/t.py", line 65, in <module> dataiter = iter(trainloader) File "E:\ProgramData\Anaconda3\envs\pytorch\lib\site-packages\torch\utils\data\dataloader.py", line 278, in __iter__ return _MultiProcessingDataLoaderIter(self) File "E:\ProgramData\Anaconda3\envs\pytorch\lib\site-packages\torch\utils\data\dataloader.py", line 682, in __init__ w.start() File "E:\ProgramData\Anaconda3\envs\pytorch\lib\multiprocessing\process.py", line 112, in start self._popen = self._Popen(self) File "E:\ProgramData\Anaconda3\envs\pytorch\lib\multiprocessing\context.py", line 223, in _Popen return _default_context.get_context().Process._Popen(process_obj) File "E:\ProgramData\Anaconda3\envs\pytorch\lib\multiprocessing\context.py", line 322, in _Popen return Popen(process_obj) File "E:\ProgramData\Anaconda3\envs\pytorch\lib\multiprocessing\popen_spawn_win32.py", line 89, in __init__ reduction.dump(process_obj, to_child) File "E:\ProgramData\Anaconda3\envs\pytorch\lib\multiprocessing\reduction.py", line 60, in dump ForkingPickler(file, protocol).dump(obj) BrokenPipeError: [Errno 32] Broken pipe Process finished with exit code 1 |
原因是windows下多线程的问题,pytorch官方也说了,修改num_workers=0即可。






最新评论
站长您好,亚马逊云咨询推广资源,望建立联系,可邮件,谢谢。
换友情链接吗?
看你的站做的挺不错的
恭喜!!太强了,硕博连读啊
雁过留毛,人过留名。
看不懂但大受震撼
每天都在战争,希望2026和平.
ZeroTier 看过多篇帖子,目前群辉、飞牛os、win11 、安卓、ubuntu ≥18.04 顺利通过,这篇相对于简单 实用、特来感谢 🙄