【深度学习常见错误手册】
当我们在进行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即可解决错误。

本文介绍了解决PyTorch在Windows系统下使用Dataloader加载数据时出现的多进程错误的方法。通过调整num_workers参数为0,确保了在不支持多进程的数据加载环境中能够正确运行。
2126

被折叠的 条评论
为什么被折叠?



