运行代码时错误提示:
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.
解决办法
-
定位到报错的代码处,比如:
在这段代码前加上:
if __name__ == '__main__':
(一般加在整个epoch的循环前面) -
将DataLoader中的num_workers改为0.