title: Pytorch torchvision.transforms execute randomly?
body: <p>I am doing this transformation:</p>
  <pre><code>self.transform = transforms.Compose( {
              transforms.Resize((224, 224)),
              transforms.ToTensor(),
              transforms.Normalize((0.485, 0.456, 0.406), (0.229, 0.224, 0.225))
          } )
  </code></pre>
  <p>and then</p>
  <pre><code>image = Image.open(img_name)
  
  if self.transform:
      image = self.transform(image)
  </code></pre>
  <p>this works for the first epoch then how the hell it crashes for the second epoch?
  why the f <code>normalize</code> getting <code>PIL-image</code> and not <code>torch.tensor</code>? is the execution of each transforms Compose items random?</p>
  <blockquote>
  <p>Traceback (most recent call last):   File
  &quot;/home/ubuntu/projects/ssl/src/train_supervised.py&quot;, line 63, in
  
  main()   File &quot;/home/ubuntu/projects/ssl/src/train_supervised.py&quot;, line 60, in main
  train()   File &quot;/home/ubuntu/projects/ssl/src/train_supervised.py&quot;, line 45, in train
  for i, data in enumerate(tqdm_):   File &quot;/home/ubuntu/anaconda3/envs/pytorch-1.11.0/lib/python3.9/site-packages/tqdm/std.py&quot;,
  line 1195, in <strong>iter</strong>
  for obj in iterable:   File &quot;/home/ubuntu/anaconda3/envs/pytorch-1.11.0/lib/python3.9/site-packages/torch/utils/data/dataloader.py&quot;,
  line 530, in <strong>next</strong>
  data = self._next_data()   File &quot;/home/ubuntu/anaconda3/envs/pytorch-1.11.0/lib/python3.9/site-packages/torch/utils/data/dataloader.py&quot;,
  line 1224, in _next_data
  return self._process_data(data)   File &quot;/home/ubuntu/anaconda3/envs/pytorch-1.11.0/lib/python3.9/site-packages/torch/utils/data/dataloader.py&quot;,
  line 1250, in _process_data
  data.reraise()   File &quot;/home/ubuntu/anaconda3/envs/pytorch-1.11.0/lib/python3.9/site-packages/torch/_utils.py&quot;,
  line 457, in reraise
  raise exception TypeError: Caught TypeError in DataLoader worker process 0. Original Traceback (most recent call last):   File
  &quot;/home/ubuntu/anaconda3/envs/pytorch-1.11.0/lib/python3.9/site-packages/torch/utils/data/_utils/worker.py&quot;, line 287, in _worker_loop
  data = fetcher.fetch(index)   File &quot;/home/ubuntu/anaconda3/envs/pytorch-1.11.0/lib/python3.9/site-packages/torch/utils/data/_utils/fetch.py&quot;, line 49, in fetch
  data = [self.dataset[idx] for idx in possibly_batched_index]   File
  &quot;/home/ubuntu/anaconda3/envs/pytorch-1.11.0/lib/python3.9/site-packages/torch/utils/data/_utils/fetch.py&quot;, line 49, in 
  data = [self.dataset[idx] for idx in possibly_batched_index]   File &quot;/home/ubuntu/projects/ssl/src/data_loader.py&quot;, line 44, in
  <strong>getitem</strong>
  image = self.transform(image)   File &quot;/home/ubuntu/anaconda3/envs/pytorch-1.11.0/lib/python3.9/site-packages/torchvision/transforms/transforms.py&quot;, line 95, in <strong>call</strong>
  img = t(img)   File &quot;/home/ubuntu/anaconda3/envs/pytorch-1.11.0/lib/python3.9/site-packages/torch/nn/modules/module.py&quot;,
  line 1110, in _call_impl
  return forward_call(*input, **kwargs)   File &quot;/home/ubuntu/anaconda3/envs/pytorch-1.11.0/lib/python3.9/site-packages/torchvision/transforms/transforms.py&quot;, line 270, in forward
  return F.normalize(tensor, self.mean, self.std, self.inplace)   File
  &quot;/home/ubuntu/anaconda3/envs/pytorch-1.11.0/lib/python3.9/site-packages/torchvision/transforms/functional.py&quot;, line 341, in normalize
  raise TypeError(f&quot;Input tensor should be a torch tensor. Got {type(tensor)}.&quot;) TypeError: Input tensor should be a torch tensor.
  Got &lt;class 'PIL.Image.Image'&gt;.</p>
  </blockquote>