1. 程式人生 > >RuntimeError: The size of tensor a (96) must match the size of tensor b (95) at non-singleton dimens

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

復現PSMNet時候出現的bug。

出錯在output = model(imgL,imgR)

一開始以為左右兩圖維度不一致。換成output = model(imgR,imgR)之後依舊報錯

翻牆查閱pytorch資料

If two tensors xy are “broadcastable”, the resulting tensor size is calculated as follows:

  • If the number of dimensions of x and y 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 and yalong 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) 

還是維度問題~