Module 'torchvision.transforms.functional' has no attribute 'get_image_size'

C1009919253: <p>While I learn <a href="https://pytorch.org/tutorials/intermediate/torchvision_tutorial.html#wrapping-up" rel="noopener nofollow ugc">TorchVision Object Detection Finetuning Tutorial</a> , I download the full  source. After running, I got error like this:</p>
<pre><code class="lang-auto">Traceback (most recent call last):
  File "C:/Users/Sandwich/source/repos/pytorch/Image_and_Video/tv-training-code.py", line 165, in &lt;module&gt;
    main()
  File "C:/Users/Sandwich/source/repos/pytorch/Image_and_Video/tv-training-code.py", line 156, in main
    train_one_epoch(model, optimizer, data_loader, device, epoch, print_freq=10)
  File "C:\Users\Sandwich\source\repos\pytorch\Image_and_Video\engine.py", line 28, in train_one_epoch
    for images, targets in metric_logger.log_every(data_loader, print_freq, header):
  File "C:\Users\Sandwich\source\repos\pytorch\Image_and_Video\utils.py", line 171, in log_every
    for obj in iterable:
  File "C:\Python38\lib\site-packages\torch\utils\data\dataloader.py", line 521, in __next__
    data = self._next_data()
  File "C:\Python38\lib\site-packages\torch\utils\data\dataloader.py", line 1203, in _next_data
    return self._process_data(data)
  File "C:\Python38\lib\site-packages\torch\utils\data\dataloader.py", line 1229, in _process_data
    data.reraise()
  File "C:\Python38\lib\site-packages\torch\_utils.py", line 425, in reraise
    raise self.exc_type(msg)
AttributeError: Caught AttributeError in DataLoader worker process 0.
Original Traceback (most recent call last):
  File "C:\Python38\lib\site-packages\torch\utils\data\_utils\worker.py", line 287, in _worker_loop
    data = fetcher.fetch(index)
  File "C:\Python38\lib\site-packages\torch\utils\data\_utils\fetch.py", line 44, in fetch
    data = [self.dataset[idx] for idx in possibly_batched_index]
  File "C:\Python38\lib\site-packages\torch\utils\data\_utils\fetch.py", line 44, in &lt;listcomp&gt;
    data = [self.dataset[idx] for idx in possibly_batched_index]
  File "C:\Python38\lib\site-packages\torch\utils\data\dataset.py", line 311, in __getitem__
    return self.dataset[self.indices[idx]]
  File "C:\Users\Sandwich\source\repos\pytorch\Image_and_Video\tv-training-code.py", line 77, in __getitem__
    img, target = self.transforms(img, target)
  File "C:\Users\Sandwich\source\repos\pytorch\Image_and_Video\transforms.py", line 26, in __call__
    image, target = t(image, target)
  File "C:\Python38\lib\site-packages\torch\nn\modules\module.py", line 1051, in _call_impl
    return forward_call(*input, **kwargs)
  File "C:\Users\Sandwich\source\repos\pytorch\Image_and_Video\transforms.py", line 37, in forward
    width, _ = F.get_image_size(image)
AttributeError: module 'torchvision.transforms.functional' has no attribute 'get_image_size'
</code></pre>
<p>I find that the module has a attribute named ‘_get_image_size’, so I amend it. Than I got error like this:</p>
<pre><code class="lang-auto">Traceback (most recent call last):
  File "C:/Users/Sandwich/source/repos/pytorch/Image_and_Video/tv-training-code.py", line 165, in &lt;module&gt;
    main()
  File "C:/Users/Sandwich/source/repos/pytorch/Image_and_Video/tv-training-code.py", line 156, in main
    train_one_epoch(model, optimizer, data_loader, device, epoch, print_freq=10)
  File "C:\Users\Sandwich\source\repos\pytorch\Image_and_Video\engine.py", line 34, in train_one_epoch
    loss_dict = model(images, targets)
  File "C:\Python38\lib\site-packages\torch\nn\modules\module.py", line 1051, in _call_impl
    return forward_call(*input, **kwargs)
  File "C:\Python38\lib\site-packages\torchvision\models\detection\generalized_rcnn.py", line 77, in forward
    images, targets = self.transform(images, targets)
  File "C:\Python38\lib\site-packages\torch\nn\modules\module.py", line 1051, in _call_impl
    return forward_call(*input, **kwargs)
  File "C:\Python38\lib\site-packages\torchvision\models\detection\transform.py", line 108, in forward
    target_index = targets[i] if targets is not None else None
IndexError: list index out of range
</code></pre>
<p>Well, I have no idea about how to deal with it.</p>

Gregory_Bourguin: <p>Hi ! I’ve got exactly the same pb (I’m using torchvision.<strong>version</strong> ‘0.10.1+cu111’<br>
Wondering if you found a solution ?</p>

C1009919253: <p>Sorry, I have no idea…<br>
I found that it’s used in an old torchvision version, so I just pass…</p>

Gregory_Bourguin: <p>Thanks for your answer.<br>
I finally managed the pb by modifying the source and using array shapes.</p>