Skip to content

Commit 1594569

Browse files
committed
Improve comments
1 parent 7d5c07d commit 1594569

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

setup.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@ def get_dist(pkgname):
111111
]
112112

113113
# Excluding 8.3.* because of https://github.com/pytorch/vision/issues/4934
114-
# TODO remove <11.3 bound and address corresponding deprecation warnings
115114
pillow_ver = " >= 5.3.0, !=8.3.*"
116115
pillow_req = "pillow-simd" if get_dist("pillow-simd") is not None else "pillow"
117116
requirements.append(pillow_req + pillow_ver)

torchvision/utils.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -186,14 +186,20 @@ def _Image_fromarray(
186186
https://pillow.readthedocs.io/en/stable/releasenotes/11.3.0.html#image-fromarray-mode-parameter
187187
"""
188188
if PILLOW_VERSION >= (11, 3):
189-
# We actually rely on the old behavior of Image.fromarray():
189+
# The actual PR that implements the deprecation has more context for why
190+
# it was done, and also points out some problems:
190191
#
191-
# new behavior: PIL will infer the image mode from the data passed in.
192-
# That is, the type and shape determines the mode.
192+
# https://github.com/python-pillow/Pillow/pull/9018
193193
#
194-
# old behiavor: The mode will change how PIL reads the image,
195-
# regardless of the data. That is, it will make the data
196-
# work with the mode.
194+
# Our use case falls into those problems. We actually rely on the old
195+
# behavior of Image.fromarray():
196+
#
197+
# new behavior: PIL will infer the image mode from the data passed
198+
# in. That is, the type and shape determines the mode.
199+
#
200+
# old behiavor: The mode will change how PIL reads the image,
201+
# regardless of the data. That is, it will make the
202+
# data work with the mode.
197203
#
198204
# Our uses of Image.fromarray() are effectively a "turn into PIL image
199205
# AND convert the kind" operation. In particular, in
@@ -211,6 +217,13 @@ def _Image_fromarray(
211217
# img = img.convert(mode)
212218
#
213219
# The resulting image has very different actual pixel values than before.
220+
#
221+
# TODO: Issue #9151. Pillow has an open PR to restore the functionality
222+
# we rely on:
223+
#
224+
# https://github.com/python-pillow/Pillow/pull/9063
225+
#
226+
# When that is part of a release, we can revisit this hack below.
214227
arr = obj.__array_interface__
215228
shape = arr["shape"]
216229
ndim = len(shape)

0 commit comments

Comments
 (0)