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 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``
posted @ 2020-01-04 12:25  mengfu188  阅读(1276)  评论(0)    收藏  举报