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

torchvision 0.4.2: test_adjust_saturation fails with pillow 7.0.0 #1835

Closed
hartb opened this issue Jan 29, 2020 · 1 comment
Closed

torchvision 0.4.2: test_adjust_saturation fails with pillow 7.0.0 #1835

hartb opened this issue Jan 29, 2020 · 1 comment

Comments

@hartb
Copy link
Contributor

hartb commented Jan 29, 2020

Test test_adjust_saturation creates an image from a small array and calls torchvision.transorms.functional.adjust_saturation to adjust the saturation to a couple different levels (0.5 and 2), and then compares the result to some hard-coded expected values.

Torchvision's adjust_saturation routine relies on PIL.ImageEnhance to do the actual work.

The results from pillow's implementation of that routine has changed between pillow 6.2.1 and 7.0.0 (at least in Anaconda's pre-built pillow packages):

$ cat test.py
import numpy as np
from PIL import Image, ImageEnhance, __version__ as PILLOW_VERSION

x_shape = [2, 2, 3]
x_data = [0, 5, 13, 54, 135, 226, 37, 8, 234, 90, 255, 1]

x_np = np.array(x_data, dtype=np.uint8).reshape(x_shape)
x_pil = Image.fromarray(x_np, mode='RGB')

print(f'Pillow version {PILLOW_VERSION}')
for saturation in [0.5, 2]:
    y_pil = ImageEnhance.Color(x_pil).enhance(saturation)
    print(f'adjust_saturation({saturation:3.1f}) => {np.array(y_pil).reshape([12])}')

(pil6) $ python test.py
Pillow version 6.2.1
adjust_saturation(0.5) => [  2   4   8  87 128 173  39  25 138 133 215  88]
adjust_saturation(2.0) => [  0   6  22   0 149 255  32   0 255   4 255   0]

(pil7) $ python test.py
Pillow version 7.0.0
adjust_saturation(0.5) => [  2   4   8  87 128 173  39  25 138 133 216  89]
adjust_saturation(2.0) => [  0   6  22   0 149 255  32   0 255   3 255   0]

Note the differences in the final 3 values between v6 and v7:

  • 133 215 88 vs 133 216 89, and
  • 4 255 0 vs 3 255 0

The output from the newer pillow version no longer matches the hard-coded values in the test, and so the test fails.

This problem is seen on both x86_64 and ppc64le.

Possible solutions migtht be any of:

  • carry canned values for each of pillow v6 and v7
  • choose an input with stable outputs across both versions
  • relax the allclose assertion to atol=1 to allow for slight differences due to rounding (i.e. to allow 1 least significant bit of difference, since these are uint8 quantities)
@datumbox
Copy link
Contributor

datumbox commented Jan 6, 2021

This issue appears to be stale, so I'm closing it. If you think it should remain open, feel free to reopen it.

@datumbox datumbox closed this as completed Jan 6, 2021
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

2 participants