RuntimeError: Sizes of tensors must match except in dimension 1. Got 61 and 60 in dimension 2

1. 背景介绍

      在训练语义分割模型时,出现以下错误:

      RuntimeError: Sizes of tensors must match except in dimension 1. Got 61 and 60 in dimension 2

 

2. 错误产生原因

      在模型中有以下操作:torch.cat(x, y)

      当x, y的尺寸不一致时,就会出现以上错误。

      进行单步调试,发现我的错误是因为图像山采样和下采样后,由于取整的方式不一样,导致的x、y的尺寸不一致。

 

3. 解决方法

      方法1:在图像输入时,宽和高最好是32的整数倍,就不会出现取整的问题。

      方法2:把x、y resize到相同的尺寸。

你可能感兴趣的:(pytorch,计算机视觉,pytorch)