Skip to content

Cannot script transforms.Resize with int argument. #3692

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
erip opened this issue Apr 19, 2021 · 2 comments
Closed

Cannot script transforms.Resize with int argument. #3692

erip opened this issue Apr 19, 2021 · 2 comments

Comments

@erip
Copy link

erip commented Apr 19, 2021

🐛 Bug

Scripting transforms.Resize with a single int argument fails while scripting with an iterable argument succeeds.

To Reproduce

Steps to reproduce the behavior:

  1. $ python -c "import torch; from torchvision import transforms; torch.jit.script(transforms.Resize((256, 256)))"
  2. Observe OK.
  3. $ python -c "import torch; from torchvision import transforms; torch.jit.script(transforms.Resize(256))"
  4. Observe not OK with following:
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/erip/miniconda3/envs/img/lib/python3.7/site-packages/torch/jit/_script.py", line 943, in script
    obj, torch.jit._recursive.infer_methods_to_compile
  File "/Users/erip/miniconda3/envs/img/lib/python3.7/site-packages/torch/jit/_recursive.py", line 391, in create_script_module
    return create_script_module_impl(nn_module, concrete_type, stubs_fn)
  File "/Users/erip/miniconda3/envs/img/lib/python3.7/site-packages/torch/jit/_recursive.py", line 452, in create_script_module_impl
    create_methods_and_properties_from_stubs(concrete_type, method_stubs, property_stubs)
  File "/Users/erip/miniconda3/envs/img/lib/python3.7/site-packages/torch/jit/_recursive.py", line 335, in create_methods_and_properties_from_stubs
    concrete_type._create_methods_and_properties(property_defs, property_rcbs, method_defs, method_rcbs, method_defaults)
RuntimeError:

resize(Tensor img, int[] size, Enum<__torch__.torchvision.transforms.functional.InterpolationMode> interpolation=Enum<InterpolationMode.BILINEAR>) -> (Tensor):
Expected a value of type 'List[int]' for argument 'size' but instead found type 'int'.
:
  File "/Users/erip/miniconda3/envs/img/lib/python3.7/site-packages/torchvision/transforms/transforms.py", line 273
            PIL Image or Tensor: Rescaled image.
        """
        return F.resize(img, self.size, self.interpolation)
               ~~~~~~~~ <--- HERE

Expected behavior

transforms.Resize should be scriptable in both cases.

Environment

PyTorch version: 1.8.0
Is debug build: False
CUDA used to build PyTorch: None
ROCM used to build PyTorch: N/A

OS: macOS 11.2.3 (x86_64)
GCC version: Could not collect
Clang version: 12.0.0 (clang-1200.0.32.29)
CMake version: version 3.14.0

Python version: 3.7 (64-bit runtime)
Is CUDA available: False
CUDA runtime version: No CUDA
GPU models and configuration: No CUDA
Nvidia driver version: No CUDA
cuDNN version: No CUDA
HIP runtime version: N/A
MIOpen runtime version: N/A

Versions of relevant libraries:
[pip3] numpy==1.20.2
[pip3] torch==1.8.0
[pip3] torchvision==0.9.0a0
[conda] libblas 3.9.0 8_mkl
[conda] libcblas 3.9.0 8_mkl
[conda] liblapack 3.9.0 8_mkl
[conda] mkl 2020.4 h08c4f10_301
[conda] numpy 1.20.2 py37h84c02c4_0
[conda] pytorch 1.8.0 cpu_py37hb93c03e_0
[conda] torchvision 0.9.0 py37h561b37a_0_cpu

Additional context

@erip
Copy link
Author

erip commented Apr 19, 2021

Ugh. This is documented in the docstring.

@erip erip closed this as completed Apr 19, 2021
@NicolasHug
Copy link
Member

Perhaps we should make it more obvious with a .. note: or a .. warning: directive?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants