美文网首页
mmdetection使用指定编号的GPU训练模型

mmdetection使用指定编号的GPU训练模型

作者: cshun | 来源:发表于2020-01-03 14:39 被阅读0次

mmdetection使用指定编号的GPU训练模型。(Dataparallel用于多卡训练)
修改mmdet/apis/train.py

# put model on gpus
model = MMDataParallel(model, device_ids=range(cfg.gpus)).cuda()

(cfg.gpus为设置的使用gpus的数量,例如gpus=4,range(cfg.gpus)则指[0,1,2,3],使用编号为0,1,2,3的显卡,并且默认模型输出显卡:output_device为第一个元素上的显卡0)

修改为

# put model on gpus
model = MMDataParallel(model, device_ids=range(4,4+cfg.gpus)).cuda(4)

cfg.gpus仍然等于4,range(4,4+cfg.gpus)则是[4,5,6,7]四块显卡,并且output_device为第一个元素上的显卡4,需要设置model.cuda(4)同步。

当然也可以修改device_ids=[1,3,5,7]等,并设置.cuda(1)即可。网上推荐设置为偶数,且batchsize大于gpu_num。

解决报错如下:

RuntimeError: module must have its parameters and buffers on device cuda:4 (device_ids[0]) but found one of them on device: cuda:0

测试test.py时:(有问题)
修改device_ids的编号即可,如下使用id为6的显卡。

    if not distributed:
        model = MMDataParallel(model, device_ids=[6])
        outputs = single_gpu_test(model, data_loader, args.show)

Dataparallel的用法参考:
Dataparallel源码解析
https://www.cnblogs.com/marsggbo/p/10962763.html

相关文章

网友评论

      本文标题:mmdetection使用指定编号的GPU训练模型

      本文链接:https://www.haomeiwen.com/subject/jnmzoctx.html