复现PSMNet时候出现的bug。
出错在output = model(imgL,imgR)
一开始以为左右两图维度不一致。换成output = model(imgR,imgR)之后依旧报错
翻墙查阅pytorch资料
If two tensors x
, y
are “broadcastable”, the resulting tensor size is calculated as follows:
- If the number of dimensions of
x
andy
are 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 of
x
andy
along 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)
还是维度问题~