zoukankan      html  css  js  c++  java
  • pytorch中使用多显卡训练以及训练时报错:expect more than 1 value per channel when training, got input size..

    pytorch在训练中使用多卡:

            conf.device = torch.device('cuda:0' if torch.cuda.is_available() else "cpu")
            conf.device_ids = list(conf.device_ids)
            self.model = torch.nn.DataParallel(self.model, device_ids=conf.device_ids)
            self.model.to(conf.device)
    

     然后在训练的命令行需要指定GPU:

    export CUDA_VISIBLE_DEVICES=4,5,6,7
    

     在pytorch内部,conf.device_ids依旧是从0开始的;

    训练的时候报错:

    是由于batchnorm层需要大于一个样本去计算其中的参数,网上搜索了解决方法是将dataloader的一个丢弃参数设置为true:

    但是我设置后依旧会报错,然后就在train里面人为修改了一下:

    如果剩下的照片为1,那么就丢掉,就可以了:

  • 相关阅读:
    MVC 4 中 WEB API 选择 返回格式
    用XML配置菜单的一种思路,附一些不太准确的测试代码
    2020.11.15(每周总结)
    2020.11.19
    2020.11.22
    2020.11.21
    2020.11.14
    202.11.13
    2020.11.20
    2020.11.17
  • 原文地址:https://www.cnblogs.com/rainsoul/p/11779176.html
Copyright © 2011-2022 走看看