Pytorch报错记录

1.BrokenPipeError

 执行以下命令时:

 a,b = iter(train_loader).next()

报错:BrokenPipeError: [Errno 32] Broken pipe

错误原因:子进程原因

On Windows the subprocesses will import (i.e. execute) the main module at start. You need to insert an if __name__ == '__main__': guard in the main module to avoid creating subprocesses recursively.
解决方法:

Please see my edited response where I did exactly that. The requirement for wrapping the code inside of if __name__ == '__main__' code isn't immediately obvoius, as it is only required for Windows machines.就是说在windows下必须将上面的代码打包在if __name__ == '__main__'语句下面。这时不会报错了。

还有人说:I also got the same error. When I set num_workers to 0, the error does not appear again. However, when I set num_workers to 1, the error is still there.即将如下:

    train_loader = data.DataLoader(dataset, batch_size=64, shuffle=True, num_workers=2, drop_last=False)

代码中的num_workers=0,但我改了以后还回报另外的错误。

猜你喜欢

转载自www.cnblogs.com/king-lps/p/10741145.html