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

Francesco_Pochetti: <p>I am running pytorch <code>0.3.0.post4</code> on Ubuntu 14.04 (conda 4.3.25, python 3.6.2, cuda 8.0).<br>
Here is what I get when importing <code>torchvision.transforms</code></p>
<pre><code class="lang-auto">&gt;&gt;&gt; from torchvision import transforms
&gt;&gt;&gt; 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']
</code></pre>
<p>As you can see most of the transforms currently <a href="http://pytorch.org/docs/master/torchvision/transforms.html" rel="nofollow noopener">documented</a> are missing, resulting in <code>AttributeError</code>s such as this one</p>
<pre><code class="lang-auto">&gt;&gt;&gt; transforms.RandomResizedCrop(224)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
&lt;ipython-input-9-5275ac2684b6&gt; in &lt;module&gt;()
----&gt; 1 transforms.RandomResizedCrop(224)

AttributeError: module 'torchvision.transforms' has no attribute 'RandomResizedCrop'
</code></pre>
<p>Am I not using the latest pytorch version or am I missing something very basic here?<br>
Thanks for the help in advance!</p>

SimonW: <p>Check your torchvision install version. The method should be in 0.3 torchvision.</p>
<p>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.</p>

Francesco_Pochetti: <p>Thanks for the reply. I didn’t know <code>torch</code> and <code>torchvision</code> were different packages.</p>
<p>I tried running <code>conda install torchvision -c soumith</code> which upgraded <code>torchvision</code> from 0.1.8 to 0.1.9.<br>
As far as I can see, googling around, the latest release is 0.2. Nowhere I could find a reference to 0.3.<br>
Do you know how to upgrade properly?</p>

Francesco_Pochetti: <p>I managed to do it uninstalling <code>torchvision</code> and resinstalling it via <code>pip</code>, which allowed me to pull the 0.2, containing the latest methods. <code>conda</code> would only pull 0.1.9</p>

SimonW: <p>My bad. Newest torchvision apparently is 0.2.</p>
<p>With conda, you should be looking at the new <code>pytorch</code> channel. Here’s the new install command: <code>conda install pytorch torchvision -c pytorch</code></p>

celdeldel: <p><a class="mention" href="/u/francesco_pochetti">@Francesco_Pochetti</a>, I had exactly the same AttributeError, I finally used ‘RandomSizedCroped’ instead of  ‘RandomResizedCrop’</p>

ptrblck: <p>Did you try to update torchvision?<br>
It should be in the current binary build.</p>
<p>Anyway, where did you find <code>RandomSizedCroped</code>?</p>

celdeldel: <p>I have tried to update torchvision by using the command line:<br>
<code>conda install torchvision -c soumith</code></p>
<p>then I got this :</p>
<pre><code class="lang-auto">Solving environment: done
# All requested packages already installed.
</code></pre>
<p>so i used the following commands in python shell :</p>
<pre><code class="lang-auto">from torchvision import transforms
dir(transforms)
</code></pre>
<p>then i got the list of function and found RandomSizedCroped</p>

ptrblck: <p>You should use the pytorch channel like <a class="mention" href="/u/simonw">@SimonW</a> said:</p>
<pre><code class="lang-auto">conda install pytorch torchvision -c pytorch
</code></pre>

celdeldel: <p>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 ?</p>

SimonW: <p>what’s your torchvision version?</p>

ptrblck: <p>If conda cannot find the latest package, you could try to update conda with <code>conda update conda</code> and then re-run the install command.</p>
<p>I think it’s almost the same, but while <code>RandomSizedCrop</code> resizes the image to its original input size, you can specify the size to which it will be resized in <code>RandomResizedCrop</code>.</p>

Saif_AlKhalidy: <p>You should use the pip install command</p>
<p>pip install opencv-torchvision-transforms-yuzhiyang</p>