使用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
即可。
本文最后更新于2020年1月13日,已超过 1 年没有更新,如果文章内容或图片资源失效,请留言反馈,我们会及时处理,谢谢!