-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
use Image.Resampling
namespace for PIL mapping
#1256
Conversation
PIL shows a deprecation warning when accessing resampling constants via the `Image` namespace. The suggested namespace is `Image.Resampling`. This commit updates `_pil_interpolation_to_str` to use the `Image.Resampling` namespace. ``` /tmp/ipykernel_11959/698124036.py:2: DeprecationWarning: NEAREST is deprecated and will be removed in Pillow 10 (2023-07-01). Use Resampling.NEAREST or Dither.NONE instead. Image.NEAREST: 'nearest', /tmp/ipykernel_11959/698124036.py:3: DeprecationWarning: BILINEAR is deprecated and will be removed in Pillow 10 (2023-07-01). Use Resampling.BILINEAR instead. Image.BILINEAR: 'bilinear', /tmp/ipykernel_11959/698124036.py:4: DeprecationWarning: BICUBIC is deprecated and will be removed in Pillow 10 (2023-07-01). Use Resampling.BICUBIC instead. Image.BICUBIC: 'bicubic', /tmp/ipykernel_11959/698124036.py:5: DeprecationWarning: BOX is deprecated and will be removed in Pillow 10 (2023-07-01). Use Resampling.BOX instead. Image.BOX: 'box', /tmp/ipykernel_11959/698124036.py:6: DeprecationWarning: HAMMING is deprecated and will be removed in Pillow 10 (2023-07-01). Use Resampling.HAMMING instead. Image.HAMMING: 'hamming', /tmp/ipykernel_11959/698124036.py:7: DeprecationWarning: LANCZOS is deprecated and will be removed in Pillow 10 (2023-07-01). Use Resampling.LANCZOS instead. Image.LANCZOS: 'lanczos', ```
@kaczmarj how far back in PIL versions does the new enum exist? |
great question -- the new enum was added in python-pillow/Pillow#5954 (merged february 18 2022). only the most recent version of pillow (version 9.1.0) has this enum. torchvision requires pillow>=5.3.0, so this would break functionality on older pillow versions. torchvision recently merged a pull request that used the new enums only if the pillow version was above 9.1. what would you like to do? perhaps we could follow torchvision's example and use the enum only if the pillow version is above 9.1. |
I'm surprised to discover that timm imports numpy and pillow despite neither being listed as dependencies in |
@adamjstewart @kaczmarj there's no difference in version of pillow supported from a compatbility standpoint, it's a deprecation warning. 9.1 is really new and there isn't even a Pillow-SIMD release of it yet(I only use that, normal Pillow is too slow to use for training). I will put up with the warning for now, doing string parsing version checks is notoriously problematic. Checking for the existence of the new enum type would be more robust and I'd accept the PR if it used that approach. |
@adamjstewart @kaczmarj looking at the torchvision bug I just filed, there's the ans why you don't do this (string checks are hard to get right in all cases even when they appear straightforward) |
@rwightman - how prescient! i'll try to submit a pr this weekend that checks for the existence of the new resampling enum and uses it only if it exists. |
Awesome, thx |
@rwightman thanks, I didn't even think about that, I made the same mistake in my library, will fix that. |
This will prevent things from breaking, but it won't silence the warning. Personally, I would use |
@rwightman corrected me, both are valid approaches. |
@rwightman - i added a commit to check for |
Should this also be done in
|
PIL version 9.1.0 shows a deprecation warning when accessing resampling constants via the
Image
namespace. The suggested namespace isImage.Resampling
. This commit updates_pil_interpolation_to_str
to use theImage.Resampling
namespace.