RuntimeError:The size of tensor a (128) must match the size of tensor b (256) at non-singleton dime

时间:2025-05-08 20:51:00

报错如上,是因为在计算损失的时候,output和target的尺寸大小不一样,所以修改的方法是查看模型参数,也就是查看output的输出大小是多少,可以使用一下方法:

from torchstat import stat
model=InpaintGenerator(1)  #1是InpaintGenerator的参数
print(model)
print(stat(model,input_size=[4,256,256]))  #input_size是输入图片的大小