AndreaCodegoni/Tiny_model_4_CD

RuntimeError: The size of tensor a (64) must match the size of tensor b (256) at non-singleton dimension 3.

runauto opened this issue · 3 comments

the problem info as follows:
Traceback (most recent call last):
File "training.py", line 223, in
run()
File "training.py", line 217, in run
save_after=1,
File "training.py", line 143, in train
training_phase(epc)
File "training.py", line 106, in training_phase
it_loss = evaluate(reference, testimg, mask)
File "training.py", line 84, in evaluate
generated_mask = model(reference, testimg).squeeze(1)
File "/home//anaconda3/envs/py370/lib/python3.7/site-packages/torch/nn/modules/module.py", line 1130, in _call_impl
return forward_call(*input, **kwargs)
File "/home//work/Tiny_model_4_CD-main/models/change_classifier.py", line 48, in forward
latents = self._decode(features)
File "/home//work/Tiny_model_4_CD-main/models/change_classifier.py", line 65, in _decode
upping = self._up[i](upping, features[j])
File "/home//anaconda3/envs/py370/lib/python3.7/site-packages/torch/nn/modules/module.py", line 1130, in _call_impl
return forward_call(*input, **kwargs)
File "/home//work/Tiny_model_4_CD-main/models/layers.py", line 121, in forward
x = x * y
RuntimeError: The size of tensor a (64) must match the size of tensor b (256) at non-singleton dimension 3

Hello,

it seems that you are doing something wrong with the dimensions in the skip connections. If you have left the network parameters unchanged perhaps you are using images that have no initial spatial size of 256x256. In any case, you have to fix the first parameter of the Upmask layers which is the spatial dimension which is the one that the tensor will assume after upsampling and which must be equal to that of the skip connection you want to pass to it. You can easily deduce these dimensions by hand or by debugging and inspecting the dimensions of the elements in the "features" vector generated at the end of the encoding phase.

I hope I have clarified the problem for you.
Let me know.

thianks for your reply,as your said,the input image size is not 256256(the image size is 10801920), so ,change the upmask layer size to fit the dimension of input image?

Sorry for the late reply.
That's right you have to play with the first parameter of the upmask layers so that the dimensions coincide. The most comfortable way as I told you is to launch a debugging session and write down the spatial dimensions by hand and then adjust the parameters.
From the size of the images you gave me, however, your images are rectangular. Beware that the network is designed for images with H = W. My advice is to resize the image, perhaps at a lower resolution in order to make the training even less heavy.
If for some reason you do not want to resize the image, then you must also intervene within Upmask by adding another parameter so that you can manage images with H different from W.

I close the issue, but feel free to write me for any other problem.