Expected more than 1 value per channel when training, got input size torch.Size

Expected more than 1 value per channel when training, got input size torch.Size

训练的时候,batch size必须大于1,但是预测的时候,batch size可以等于1

原因:

因为模型中用了batchnomolization,训练中用batch训练的时候当前batch恰好只含一个sample,而由于BatchNorm操作需要多于一个数据计算平均值,因此造成该错误。

解决方法:

1. 加大batch_size

2.网络设置eval模式:

model=MyModel()
model.eval()

猜你喜欢

转载自blog.csdn.net/qq_39237205/article/details/124201594
今日推荐