-
Notifications
You must be signed in to change notification settings - Fork 7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AttributeError: module 'torchvision.transforms.functional' has no attribute 'get_image_size' #4328
Comments
Actually even the workaround is not working. Something seems broken. |
@praveern The method was added just yesterday so it might not be available on nightly yet. I would recommend installing it from source and trying again. If you continue facing problems, please provide the minimum code that would allow us to reproduce the problem along with information about the version you are using etc. From what I see the following works find on latest
|
Hello @datumbox I'm using the latest stable build v0.10 (pytorch version 1.9.0+cu10.2) (as per the installation section in getting started). Regarding code, I am literally using the Pytorch tutorial as it is, with only tweaks being Google Drive paths to data and model checkpoint storage locations. |
The latest stable version version of TorchVsion does not have the If you continue having issues using the latest development version, send me a standalone minimal snippet that reproduces the issue so that we can investigate. |
Okay, so I switched my environment to use the LTS version (pip install torch==1.8.2+cu102 torchvision==0.9.2+cu102 torchaudio===0.8.2 -f https://download.pytorch.org/whl/lts/1.8/torch_lts.html) and the error still persists. As for standalone snippet, I think these specific cells of code should help:
Source - "vision/references/detection/transforms.py"
--------------------------------------------------------------------------
|
The reason why you get issues is because you are trying to use code from the latest development branch with an old stable version of TorchVision. When you mix code from different versions you can get issues. As I explained earlier, the PR #4321 which renamed the private method You are currently trying to call a method that does not exist on the TorchVision version you are using. A quick workaround is to replace I believe this answers your question and thus I'll close the ticket. If you have further concerns feel free to reopen it. |
Ouch. I just realized I really was doing a very silly mistake. 😅 |
@praveern hey don't worry about it! It's end of week, mistakes happen. 😀 |
Private function _get_image_size was changed to public in torchvision v0.11. The use of torchvision v0.11 and above will result in the following error: pytorch/vision#4328
🐛 Bug
AttributeError Traceback (most recent call last)
in ()
40
41 for epoch in range(num_epochs):
---> 42 train_one_epoch(model, optimizer, data_loader, device, epoch, print_freq=10)
43 lr_scheduler.step()
44 # evaluate on the test dataset
5 frames
/usr/local/lib/python3.7/dist-packages/torch/_utils.py in reraise(self)
423 # have message field
424 raise self.exc_type(message=msg)
--> 425 raise self.exc_type(msg)
426
427
AttributeError: Caught AttributeError in DataLoader worker process 0.
Original Traceback (most recent call last):
File "/usr/local/lib/python3.7/dist-packages/torch/utils/data/_utils/worker.py", line 287, in _worker_loop
data = fetcher.fetch(index)
File "/usr/local/lib/python3.7/dist-packages/torch/utils/data/_utils/fetch.py", line 44, in fetch
data = [self.dataset[idx] for idx in possibly_batched_index]
File "/usr/local/lib/python3.7/dist-packages/torch/utils/data/_utils/fetch.py", line 44, in
data = [self.dataset[idx] for idx in possibly_batched_index]
File "/usr/local/lib/python3.7/dist-packages/torch/utils/data/dataset.py", line 311, in getitem
return self.dataset[self.indices[idx]]
File "/usr/local/lib/python3.7/dist-packages/torch/utils/data/dataset.py", line 311, in getitem
return self.dataset[self.indices[idx]]
File "", line 83, in getitem
image, target = self._transforms(image, target)
File "/content/transforms.py", line 26, in call
image, target = t(image, target)
File "/usr/local/lib/python3.7/dist-packages/torch/nn/modules/module.py", line 1051, in _call_impl
return forward_call(*input, **kwargs)
File "/content/transforms.py", line 36, in forward
width, _ = F.get_image_size(image)
AttributeError: module 'torchvision.transforms.functional' has no attribute 'get_image_size'
To Reproduce
Steps to reproduce the behavior:
torchvision.transforms.functional is not allowing access to the public method in the same file)
Expected behavior
The public method "get_image_size" should be accessed normally (I had to remove the alias "F" and explicitly call the method).
Environment
Google Colab (libraries are up to date)
cc @vfdev-5 @datumbox
The text was updated successfully, but these errors were encountered: