当前位置:   article > 正文

RuntimeError: DataLoader worker (pid(s) xxxx,xxxx ) exited unexpectedly_raise runtimeerror('dataloader worker (pid(s) {})

raise runtimeerror('dataloader worker (pid(s) {}) exited unexpectedly'.forma

RuntimeError: DataLoader worker (pid(s) xxxx,xxxx ) exited unexpectedly(运行时错误:DataLoader工作进程(pid(s)xxxx,xxxx意外退出)

运行时错误: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()
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20

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
        
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14

以及

    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]
  • 1
  • 2
  • 3

原因是在linux系统中可以使用多个子进程加载数据,而在windows系统中不能。所以在windows中要将DataLoader中的num_workers设置为0或者采用默认为0的设置。但是错误回溯指向文件trainer.py的代码段中没有num_works相关代码,无法使用num_works=0的方法。但是

报错中提到了如下方法

if __name__ == '__main__':
  • 1

即将此代码插入需要运行的代码最前边。

解决(别忘记缩进)

改完代码如下所示:

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()

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26

运行成功后如下所示

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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Cpp五条/article/detail/562735
推荐阅读
相关标签
  

闽ICP备14008679号