Pytorch的DataLoader多线程读取问题

当在 DataLoadernum_workers 设置为 >0 时会启动多线程读取

报出错误:RuntimeError: DataLoader worker (pid(s) 10160) exited unexpectedly

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.

解决方法:

我是在测试 Dataloader 用法的时候出现的该错误

然后在要执行的代码前加 if __name__ == '__main__':

就可以了

猜你喜欢

转载自blog.csdn.net/qq_40860934/article/details/110874887