AttributeError: module 'torchvision.transforms' has no attribute 'RandomResizedCrop'

I am running pytorch 0.3.0.post4 on Ubuntu 14.04 (conda 4.3.25, python 3.6.2, cuda 8.0).
Here is what I get when importing torchvision.transforms

>>> from torchvision import transforms
>>> dir(transforms)

['CenterCrop',
 'Compose',
 'Image',
 'ImageOps',
 'Lambda',
 'Normalize',
 'Pad',
 'RandomCrop',
 'RandomHorizontalFlip',
 'RandomSizedCrop',
 'Scale',
 'ToPILImage',
 'ToTensor',
 '__builtins__',
 '__cached__',
 '__doc__',
 '__file__',
 '__loader__',
 '__name__',
 '__package__',
 '__spec__',
 'division',
 'math',
 'np',
 'numbers',
 'random',
 'torch',
 'types']

As you can see most of the transforms currently documented are missing, resulting in AttributeErrors such as this one

>>> transforms.RandomResizedCrop(224)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-9-5275ac2684b6> in <module>()
----> 1 transforms.RandomResizedCrop(224)

AttributeError: module 'torchvision.transforms' has no attribute 'RandomResizedCrop'

Am I not using the latest pytorch version or am I missing something very basic here?
Thanks for the help in advance!

Check your torchvision install version. The method should be in 0.3 torchvision.

Btw, as an reminder, when such error happens, be sure to check doc of the correct version. The one you linked is master, rather than 0.3. That said, the method should be in 0.3 as well.

1 Like

Thanks for the reply. I didn’t know torch and torchvision were different packages.

I tried running conda install torchvision -c soumith which upgraded torchvision from 0.1.8 to 0.1.9.
As far as I can see, googling around, the latest release is 0.2. Nowhere I could find a reference to 0.3.
Do you know how to upgrade properly?

I managed to do it uninstalling torchvision and resinstalling it via pip, which allowed me to pull the 0.2, containing the latest methods. conda would only pull 0.1.9

2 Likes

My bad. Newest torchvision apparently is 0.2.

With conda, you should be looking at the new pytorch channel. Here’s the new install command: conda install pytorch torchvision -c pytorch

1 Like

@Francesco_Pochetti, I had exactly the same AttributeError, I finally used ‘RandomSizedCroped’ instead of ‘RandomResizedCrop’

Did you try to update torchvision?
It should be in the current binary build.

Anyway, where did you find RandomSizedCroped?

I have tried to update torchvision by using the command line:
conda install torchvision -c soumith

then I got this :

Solving environment: done
# All requested packages already installed.

so i used the following commands in python shell :

from torchvision import transforms
dir(transforms)

then i got the list of function and found RandomSizedCroped

You should use the pytorch channel like @SimonW said:

conda install pytorch torchvision -c pytorch
1 Like

I have also tried like this, but I know the package was already there. But it’s now working with RandomSizedCroped, I believe it’s the same right ?

what’s your torchvision version?

If conda cannot find the latest package, you could try to update conda with conda update conda and then re-run the install command.

I think it’s almost the same, but while RandomSizedCrop resizes the image to its original input size, you can specify the size to which it will be resized in RandomResizedCrop.

1 Like

You should use the pip install command

pip install opencv-torchvision-transforms-yuzhiyang