【深度学习常见错误手册】
当我们在进行PyTorch训练网络模型时,在对数据处理这一块可能会出错,相关Dataloader函数如下:
在运行时可能会出现下图的错误:
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.
这是因为在linux系统中可以使用多个子进程加载数据,而在windows系统中不能。在windows系统中需要将进程数设置为单进程,所以我们需要将数据处理语句这部分的参数 num_workers=2
改为 num_workers=0
即可解决错误。