pytorch报错:ValueError: Expected more than 1 value per channel when training, got input size [1,8,1,1]

问题:在用pytorch训练模型的过程中如果出现如下错误:
Expected more than 1 value per channel when training, got input size torch.Size([1, 8, 1, 1])

修改方式:从dataset中删掉最后一个sample。

问题分析:模型中用了batchnomolization,训练中用batch训练的时候,最后一个sample的batchsize不是8或8的整数倍,比如dataset的总样本数为17,你的batch_size为8,最后一个sample就会报这样的错误。

推理过程:如果推理过程报同样的错误,就在加载模型参数后,加上net.eval(),这样会采用训练时的平均u和方差。

参考:https://blog.csdn.net/u011622208/article/details/85230847

发布了36 篇原创文章 · 获赞 23 · 访问量 4万+

猜你喜欢

转载自blog.csdn.net/yy2yy99/article/details/105214693
今日推荐