Errors using transforms

Brian_Asimba: <p>I am performing transforms an images for a dog classifier and I am getting an error. Here is the code and the error I am getting:</p>
<p>import os<br>
from torchvision import datasets<br>
from torchvision import datasets<br>
from PIL import ImageFile</p>
<h3>TODO: Write data loaders for training, validation, and test sets</h3>
<p>ImageFile.LOAD_TRUNCATED_IMAGES = True</p>
<h1>number of subprocesses to use for data loading</h1>
<p>num_workers = 0</p>
<h1>batch_sizes</h1>
<p>batch_size = 20</p>
<h2>Specify appropriate transforms, and</h2>
<p>transforms ={</p>
<pre><code>'train' : transforms.Compose([transforms.Resize(256),
                              transforms.RandomResizedCrop(224),
                              transforms.RandomHorizontalFlip(),
                              transforms.RandomRotation(10),
                              transforms.RandomVerticalFlip(),
                              transforms.ToTensor(),
                              transforms.Normalize(mean=[0.485, 0.456, 0.406],
                                                  std=[0.229,0.224,0.225])]),
                              
'valid' : transforms.Compose([transforms.Resize(256),
                              transforms.RandomResizedCrop(224),
                              transforms.RandomHorizontalFlip(),
                              transforms.RandomRotation(10),
                              transforms.RandomVerticalFlip(),
                              transforms.ToTensor(),
                              transforms.Normalize(mean=[0.485, 0.456, 0.406],
                                                  std=[0.229,0.224,0.225])]),
                              
'test' : transforms.Compose([transforms.Resize(256),
                              transforms.RandomResizedCrop(224),
                              transforms.RandomHorizontalFlip(),
                              transforms.RandomRotation(10),
                              transforms.RandomVerticalFlip(),
                              transforms.ToTensor(),
                              transforms.Normalize(mean=[0.485, 0.456, 0.406],
                                                  std=[0.229,0.224,0.225])])
</code></pre>
<p>}</p>
<p>Image_datasets = {x: datasets.ImageFolder(os.path.join(‘dogImages’,y),transforms[xy])<br>
for x in[‘train’, ‘valid’,‘test’]}</p>
<p>data_loaders = {x: torch.utils.data.DataLoader(Image_datasets, batch_size=batch_size, shuffle=True,<br>
num_workers=num_workers)<br>
for x in[‘train’, ‘valid’,‘test’]}</p>
<p>Error:</p>
<pre><code>                             ---------------------------------------------------------------------------
</code></pre>
<p>AttributeError                            Traceback (most recent call last)<br>
 in <br>
15 transforms ={<br>
16<br>
—&gt; 17     ‘train’ : transforms.Compose([transforms.Resize(256),<br>
18                                   transforms.RandomResizedCrop(224),<br>
19                                   transforms.RandomHorizontalFlip(),</p>
<p>AttributeError: ‘dict’ object has no attribute ‘Compose’</p>

ptrblck: <p>It seems you are redefining the <code>transforms</code> variable with your <code>dict</code>.<br>
Change the name of the <code>dict</code> to <code>transform_dict</code> or something else and rerun the code.</p>