RuntimeError: The size of tensor a (96) must match the size of tensor b (95) at non-singleton dimens

发布于 2019-09-26 作者 风铃 316次 浏览 版块 前端

复现PSMNet时候出现的bug。

出错在output = model(imgL,imgR)

一开始以为左右两图维度不一致。换成output = model(imgR,imgR)之后依旧报错

翻墙查阅pytorch资料


If two tensorsx,yare “broadcastable”, the resulting tensor size is calculated as follows:

  • If the number of dimensions ofxandyare not equal, prepend 1 to the dimensions of the tensor with fewer dimensions to make them equal length.
  • Then, for each dimension size, the resulting dimension size is the max of the sizes ofxandyalong that dimension.
也就是说维度不一样~

再细看报错log:

Traceback (most recent call last):
File "submission.py", line 122, in <module>
main()
File "submission.py", line 113, in main
pred_disp = test(imgL,imgR)
File "submission.py", line 84, in test
output = model(imgR,imgR)
File "/usr/local/lib/python2.7/dist-packages/torch/nn/modules/module.py", line 357, in __call__
result = self.forward(*input, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/torch/nn/parallel/data_parallel.py", line 71, in forward
return self.module(*inputs[0], **kwargs[0])
File "/usr/local/lib/python2.7/dist-packages/torch/nn/modules/module.py", line 357, in __call__
result = self.forward(*input, **kwargs)
File "/home/lvhao/PSMNet-master/models/stackhourglass.py", line 124, in forward
out1, pre1, post1 = self.dres2(cost0, None, None)
File "/usr/local/lib/python2.7/dist-packages/torch/nn/modules/module.py", line 357, in __call__
result = self.forward(*input, **kwargs)
File "/home/lvhao/PSMNet-master/models/stackhourglass.py", line 46, in forward
post = F.relu(self.conv5(out)+pre, inplace=True)

还是维度问题~


收藏
暂无回复