当前位置:   article > 正文

RuntimeError: invalid argument 0: Sizes of tensors must match except in dimension 0. Got 306 and 300

runtimeerror: invalid argument 0: sizes of tensors must match except in dime

错题提示:RuntimeError: invalid argument 0: Sizes of tensors must match except in dimension 0. Got 306 and 300 in dimension 3 at /pytorch/aten/src/TH/generic/THTensor.cpp:689

经过排查后发现是torchvision.transoforms.Resize的问题,Resize注释如下,如果传进单个数字size,只会令最小的边resize成传入的数字。如图片height > width,然后图片会被resize为(size * height / width, size),当batch_size>1时可能会抛异常

class Resize(builtins.object)
 |  Resize(size, interpolation=2)
 |
 |  Resize the input PIL Image to the given size.
 |
 |  Args:
 |      size (sequence or int): Desired output size. If size is a sequence like
 |          (h, w), output size will be matched to this. If size is an int,
 |          smaller edge of the image will be matched to this number.
 |          i.e, if height > width, then image will be rescaled to
 |          (size * height / width, size)
 |      interpolation (int, optional): Desired interpolation. Default is
 |          ``PIL.Image.BILINEAR``
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家自动化/article/detail/149621
推荐阅读
相关标签
  

闽ICP备14008679号