Skip to content

Proper error description for float resize dims in tv.transforms.Resize #98287

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
MovsisyanM opened this issue Apr 4, 2023 · 6 comments
Closed
Labels
actionable good first issue module: nn Related to torch.nn module: python frontend For issues relating to PyTorch's Python frontend triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module

Comments

@MovsisyanM
Copy link

MovsisyanM commented Apr 4, 2023

🚀 The feature, motivation and pitch

I came across an obscure error message when trying to resize an image:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-55-e056f4a6fffd> in <module>
      2     img = tio.read_image(image_paths.location[i])
      3     resizer = tv.transforms.Resize(((fixed_h), int(fixed_w)))
----> 4     img = resizer(img)
      5     #img = tv.transforms.Resize((int(fixed_h), int(fixed_w)))(img.float())
      6     shape = img.shape

/usr/lib/python3/dist-packages/torch/nn/modules/module.py in _call_impl(self, *input, **kwargs)
   1108         if not (self._backward_hooks or self._forward_hooks or self._forward_pre_hooks or _global_backward_hooks
   1109                 or _global_forward_hooks or _global_forward_pre_hooks):
-> 1110             return forward_call(*input, **kwargs)
   1111         # Do not call functions when jit is used
   1112         full_backward_hooks, non_full_backward_hooks = [], []

/usr/lib/python3/dist-packages/torchvision/transforms/transforms.py in forward(self, img)
    347             PIL Image or Tensor: Rescaled image.
    348         """
--> 349         return F.resize(img, self.size, self.interpolation, self.max_size, self.antialias)
    350 
    351     def __repr__(self) -> str:

/usr/lib/python3/dist-packages/torchvision/transforms/functional.py in resize(img, size, interpolation, max_size, antialias)
    436         return F_pil.resize(img, size=size, interpolation=pil_interpolation, max_size=max_size)
    437 
--> 438     return F_t.resize(img, size=size, interpolation=interpolation.value, max_size=max_size, antialias=antialias)
    439 
    440 

/usr/lib/python3/dist-packages/torchvision/transforms/functional_tensor.py in resize(img, size, interpolation, max_size, antialias)
    488             img = torch.ops.torchvision._interpolate_bicubic2d_aa(img, [new_h, new_w], align_corners=False)
    489     else:
--> 490         img = interpolate(img, size=[new_h, new_w], mode=interpolation, align_corners=align_corners)
    491 
    492     if interpolation == "bicubic" and out_dtype == torch.uint8:

/usr/lib/python3/dist-packages/torch/nn/functional.py in interpolate(input, size, scale_factor, mode, align_corners, recompute_scale_factor, antialias)
   3917         if antialias:
   3918             return torch._C._nn._upsample_bilinear2d_aa(input, output_size, align_corners, scale_factors)
-> 3919         return torch._C._nn.upsample_bilinear2d(input, output_size, align_corners, scale_factors)
   3920     if input.dim() == 5 and mode == "trilinear":
   3921         assert align_corners is not None

TypeError: upsample_bilinear2d() received an invalid combination of arguments - got (Tensor, list, bool, NoneType), but expected one of:
 * (Tensor input, tuple of ints output_size, bool align_corners, tuple of floats scale_factors)
      didn't match because some of the arguments have invalid types: (Tensor, !list!, bool, !NoneType!)
 * (Tensor input, tuple of ints output_size, bool align_corners, float scales_h, float scales_w, *, Tensor out)

From this, I couldn't tell that the shape I wanted to resize to was provided using floats instead of ints. This shouldn't be a hard thing to implement. Thanks for your time

Alternatives

No response

Additional context

No response

cc @albanD @mruberry @jbschlosser @walterddr @mikaylagawarecki

@ezyang ezyang added module: nn Related to torch.nn triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module module: python frontend For issues relating to PyTorch's Python frontend good first issue labels Apr 5, 2023
@ezyang
Copy link
Contributor

ezyang commented Apr 5, 2023

see #87601 for some improvements, but I guess it's not enough? (Actually I feel this one should have been addressed on master)

@pbanavara
Copy link

Looking into this as it is tagged as a good first issue to contribute.
The ideal message should indicate that the second argument - output_size should be tuple of floats instead of tuple of ints ?

@ezyang
Copy link
Contributor

ezyang commented Apr 7, 2023

yes, we want to print what kind of list we were given

@MovsisyanM
Copy link
Author

Looking into this as it is tagged as a good first issue to contribute. The ideal message should indicate that the second argument - output_size should be tuple of floats instead of tuple of ints ?

It should be a tuple of ints, however a tuple of floats were given

@sambhavnoobcoder
Copy link

sambhavnoobcoder commented May 23, 2023

just confirming, is this issue still open or has it been resolved? i would like to give it a go as well. I am new to the Pytorch and open-source community in general and it would be appreciable if someone pointed me in the right direction.

@mikaylagawarecki
Copy link
Contributor

mikaylagawarecki commented May 23, 2023

@sambhavnoobcoder It looks like #99243 was opened to address this issue though it hasn't been landed yet. You can take a look at other issues marked with the label actionable to find other actionable issues if you would like to tackle them

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
actionable good first issue module: nn Related to torch.nn module: python frontend For issues relating to PyTorch's Python frontend triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants