Skip to content
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

Setting InterpolationMode.NEAREST_EXACT to interpolation argument of RandomRotation() works against the error message #8824

Open
hyperkai opened this issue Dec 23, 2024 · 0 comments

Comments

@hyperkai
Copy link

🐛 Describe the bug

Setting InterpolationMode.BOX to interpolation argument of RandomRotation() gets the error message as shown below:

from torchvision.datasets import OxfordIIITPet
from torchvision.transforms.v2 import RandomRotation
from torchvision.transforms.functional import InterpolationMode

rr = RandomRotation(degrees=[90.0, 90.0], interpolation=InterpolationMode.BOX)
                                        # ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ 
import matplotlib.pyplot as plt

plt.imshow(X=rr(my_data[0][0])) # Error
plt.show()

ValueError: Image.Resampling.BOX (4) cannot be used. Use Image.Resampling.NEAREST (0), Image.Resampling.BILINEAR (2) or Image.Resampling.BICUBIC (3)

But setting InterpolationMode.NEAREST_EXACT to interpolation argument of RandomRotation() works against the error message as shown below:

from torchvision.datasets import OxfordIIITPet
from torchvision.transforms.v2 import RandomRotation
from torchvision.transforms.functional import InterpolationMode

rr = RandomRotation(degrees=[90.0, 90.0], interpolation=InterpolationMode.NEAREST_EXACT)
                                        # ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ 
import matplotlib.pyplot as plt

plt.imshow(X=rr(my_data[0][0]))
plt.show()

Screenshot 2024-12-24 073036

So, the error message should also have Image.Resampling.NEAREST_EXACT (1) as shown below:

ValueError: Image.Resampling.BOX (4) cannot be used. Use Image.Resampling.NEAREST (0), Image.Resampling.NEAREST_EXACT (1), Image.Resampling.BILINEAR (2) or Image.Resampling.BICUBIC (3)

Versions

import torchvision

torchvision.__version__ # '0.20.1+cpu'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant