使用pytorch搭建网络模型时,报错 :
Expected input batch_size (1) to match target batch_size (2)
报错位置是在求loss时
报错原因:
网络的输出层结果不匹配
测试过程:
RuntimeError: 1only batches of spatial targets supported but got targets of size : : xx
排故:
在网络的中间层打印shape
最后问题的解决是通过添加:
x = x.view(-1, 256*2)