File tree Expand file tree Collapse file tree
tensorflow_datasets/core/utils Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -177,16 +177,19 @@ def create_thumbnail(
177177 if use_colormap : # Apply the colormap first as it modify the shape/dtype
178178 ex = apply_colormap (ex )
179179
180- _ , _ , c = ex .shape
180+ # PIL.Image.fromarray doesn't support uint16 for >1 channels.
181+ # https://github.com/python-pillow/Pillow/blob/11.0.0/src/PIL/Image.py#L3225
182+ if ex .dtype == np .uint16 :
183+ ex = (ex / 257 ).astype (np .uint8 )
184+
185+ c = ex .shape [- 1 ] if ex .ndim == 3 else 1
181186 postprocess = _postprocess_noop
182187 if c == 1 :
183188 ex = ex .squeeze (axis = - 1 )
184189 mode = 'L'
185- elif ex .dtype == np .uint16 :
186- mode = 'I;16'
187- postprocess = _postprocess_convert_rgb
188190 else :
189191 mode = None
192+ postprocess = _postprocess_convert_rgb
190193 img = PIL_Image .fromarray (ex , mode = mode )
191194 img = postprocess (img )
192195 if default_dimensions :
You can’t perform that action at this time.
0 commit comments