question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

transforms.RandomRotation with Tensors leads to an error

See original GitHub issue

🐛 Bug

Originally (vision/nightly), when torchvision.transforms.RandomRotation is used with a Tensor of shape (C, H, W), without a fill argument, we get a following error:

Error
Traceback (most recent call last):
File "repr1.py", line 9, in <module>
  tensor = torchvision.transforms.RandomRotation(45)(tensor)
File "/home/stratum/miniconda3/envs/pytorch-cpu-nightly/lib/python3.6/site-packages/torch/nn/modules/module.py", line 889, in _call_impl
  result = self.forward(*input, **kwargs)
File "/home/stratum/miniconda3/envs/pytorch-cpu-nightly/lib/python3.6/site-packages/torchvision/transforms/transforms.py", line 1236, in forward
  fill = [float(f) for f in fill]
TypeError: 'NoneType' object is not iterable

To Reproduce

Steps to reproduce the behavior:

import torch
import torchvision
tensor = torch.rand(3, 224, 224)
tensor = torchvision.transforms.RandomRotation(45)(tensor)
print(tensor.shape)

or

import torch
import torchvision
tensor = torch.rand(3, 224, 224)
transforms = torch.nn.Sequential(
    torchvision.transforms.RandomRotation(45)
)
transformed = transforms(tensor)
print(tensor.shape)

Expected behavior

torch.Size([3, 224, 224])

Environment

Environment
Collecting environment information...
PyTorch version: 1.8.0.dev20210124
Is debug build: False
CUDA used to build PyTorch: Could not collect
ROCM used to build PyTorch: N/A

OS: Manjaro Linux (x86_64)
GCC version: (GCC) 10.2.0
Clang version: Could not collect
CMake version: version 3.19.3

Python version: 3.6 (64-bit runtime)
Is CUDA available: False
CUDA runtime version: Could not collect
GPU models and configuration: GPU 0: GeForce GTX 1660 Ti
Nvidia driver version: 460.32.03
cuDNN version: Probably one of the following:
/usr/lib/libcudnn.so.8.0.5
/usr/lib/libcudnn_adv_infer.so.8.0.5
/usr/lib/libcudnn_adv_train.so.8.0.5
/usr/lib/libcudnn_cnn_infer.so.8.0.5
/usr/lib/libcudnn_cnn_train.so.8.0.5
/usr/lib/libcudnn_ops_infer.so.8.0.5
/usr/lib/libcudnn_ops_train.so.8.0.5
HIP runtime version: N/A
MIOpen runtime version: N/A

Versions of relevant libraries:
[pip3] numpy==1.19.2
[pip3] torch==1.8.0.dev20210124
[pip3] torchaudio==0.8.0a0+e38b122
[pip3] torchvision==0.9.0.dev20210124
[conda] blas                      1.0                         mkl
[conda] cpuonly                   1.0                           0    pytorch-nightly
[conda] mkl                       2020.2                      256
[conda] mkl-service               2.3.0            py36he8ac12f_0
[conda] mkl_fft                   1.2.0            py36h23d657b_0
[conda] mkl_random                1.1.1            py36h0573a6f_0
[conda] numpy                     1.19.2           py36h54aff64_0
[conda] numpy-base                1.19.2           py36hfa32c7d_0
[conda] pytorch                   1.8.0.dev20210124     py3.6_cpu_0  [cpuonly]  pytorch-nightly
[conda] torchaudio                0.8.0.dev20210124            py36    pytorch-nightly
[conda] torchvision               0.9.0.dev20210124        py36_cpu  [cpuonly]  pytorch-nightly

Additional context

I proposed a fix in #3303

Hope this helps!

cc @vfdev-5

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
vfdev-5commented, Jan 27, 2021

@voldemortX test for a case when fill is passed with None? (RandomPerspective(fill=None))

On second thought, if set default to 0, then maybe other than this only the documentation needs changing? @vfdev-5

And ensure that fill is not optional anymore and is not None. As default becomes 0, it is a sort of breaking change as there may be some folks who set it exlicitly as None.

As for fillcolor, it is a deprecated arg and should remain None. (see https://github.com/pytorch/vision/issues/2479 for details)

1reaction
tonystratumcommented, Jan 27, 2021

RandomPerspective

Traceback (most recent call last):
  File "repr2.py", line 10, in <module>
    transformed = transforms(tensor)
  File "/home/stratum/miniconda3/envs/pytorch-cpu-nightly/lib/python3.6/site-packages/torch/nn/modules/module.py", line 889, in _call_impl
    result = self.forward(*input, **kwargs)
  File "/home/stratum/miniconda3/envs/pytorch-cpu-nightly/lib/python3.6/site-packages/torch/nn/modules/container.py", line 119, in forward
    input = module(input)
  File "/home/stratum/miniconda3/envs/pytorch-cpu-nightly/lib/python3.6/site-packages/torch/nn/modules/module.py", line 889, in _call_impl
    result = self.forward(*input, **kwargs)
  File "/home/stratum/miniconda3/envs/pytorch-cpu-nightly/lib/python3.6/site-packages/torchvision/transforms/transforms.py", line 707, in forward
    fill = [float(f) for f in fill]
TypeError: 'NoneType' object is not iterable
Read more comments on GitHub >

github_iconTop Results From Across the Web

Pytorch transforms.RandomRotation() does not work on ...
The full error I got when I execute this sample code above on Google Colab. TypeError Traceback (most recent call last) <ipython-input-1- ...
Read more >
torchvision.transforms - PyTorch
Randomly flipped image. Performs a random perspective transformation of the given image with a given probability. The image can be a PIL Image...
Read more >
tf.keras.layers.RandomRotation | TensorFlow v2.11.0
A preprocessing layer which randomly rotates images during training.
Read more >
Transforms — MONAI 1.0.1 Documentation
log_stats ( bool ) – whether to log the detailed information of data and applied transform when error happened, for NumPy array and...
Read more >
4. Transfer Learning and Other Tricks - Programming PyTorch ...
In these cases, we can create a custom transform that operates on either PIL image data or a tensor. Such a class has...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found