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

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, 问题解决。

猜你喜欢

转载自blog.csdn.net/weixin_44790486/article/details/106641833