赞
踩
运行时错误:DataLoader工作进程(PID)xxxx,xxxx意外退出
在win10上运行超分辨率DRN算法里面的main.py文件遇到此问题,其代码如下
import utility import data import model import loss from option import args from checkpoint import Checkpoint from trainer import Trainer utility.set_seed(args.seed) checkpoint = Checkpoint(args) if checkpoint.ok: loader = data.Data(args) model = model.Model(args, checkpoint) loss = loss.Loss(args, checkpoint) if not args.test_only else None t = Trainer(args, loader, model, loss, checkpoint) while not t.terminate(): t.train() t.test() checkpoint.done()
DRN的所有源代码的链接在这,这些代码本来是在linux系统下运行的
https://github.com/guoyongcs/DRN
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
以及
raise RuntimeError('DataLoader worker (pid(s) {}) exited unexpectedly'.format(pids_str))
RuntimeError: DataLoader worker (pid(s) 8600) exited unexpectedly
0%| | 0/5 [00:05<?, ?it/s]
原因是在linux系统中可以使用多个子进程加载数据,而在windows系统中不能。所以在windows中要将DataLoader中的num_workers设置为0或者采用默认为0的设置。但是错误回溯指向文件trainer.py的代码段中没有num_works
相关代码,无法使用num_works=0
的方法。但是
if __name__ == '__main__':
即将此代码插入需要运行的代码最前边。
改完代码如下所示:
import utility import data import model import loss from option import args from checkpoint import Checkpoint from trainer import Trainer #以上不变 if __name__ == '__main__':#左边是插入的代码 #以下是原来的代码,全体向右缩进即可 utility.set_seed(args.seed) checkpoint = Checkpoint(args) if checkpoint.ok: loader = data.Data(args) model = model.Model(args, checkpoint) loss = loss.Loss(args, checkpoint) if not args.test_only else None t = Trainer(args, loader, model, loss, checkpoint) while not t.terminate(): t.train() t.test() checkpoint.done()
运行成功后如下所示
Making model...
Loading model from DRNS4x.pt
The number of parameters is 4.80M
Evaluation:
100%|█████████████████████████████████████████████| 5/5 [01:08<00:00, 13.74s/it]
[Set5 x4] PSNR: 32.68 (Best: 32.68 @epoch 1)
Total time: 68.70s
Process finished with exit code 0
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。