ValueError: Expected more than 1 value per channel when training, got input size…

        pytorch 在训练时使用多卡,会出现ValueError: Expected more than 1 value per channel when training, got input 这个错误
        由于batchnorm层需要大于一个样本去计算其中的参数,解决方法是将dataloader的一个丢弃参数设置为true

trainloader = data.DataLoader(db_train, batch_size= args.batch_size, shuffle=True, num_workers=0,drop_last=True)

         在data.DataLoader里面加入drop_last=True, 问题解决。

Logo

技术共进,成长同行——讯飞AI开发者社区

更多推荐