解决RuntimeError: An attempt has been made to start a new process before...办法

【深度学习常见错误手册】

当我们在进行PyTorch训练网络模型时,在对数据处理这一块可能会出错,相关Dataloader函数如下:

解决RuntimeError: An attempt has been made to start a new process before...办法_第1张图片

在运行时可能会出现下图的错误:

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.

解决RuntimeError: An attempt has been made to start a new process before...办法_第2张图片

这是因为在linux系统中可以使用多个子进程加载数据,而在windows系统中不能。在windows系统中需要将进程数设置为单进程,所以我们需要将数据处理语句这部分的参数 num_workers=2改为 num_workers=0即可解决错误。

解决RuntimeError: An attempt has been made to start a new process before...办法_第3张图片

你可能感兴趣的:(深度学习常见错误汇总,pytorch,人工智能,python,深度学习)