Skip to content

Conversation

@0AnshuAditya0
Copy link

Description

Fixes #11148

This PR fixes test failures in ImageFeatureTest when using Pillow 12.0.0. The tests were failing with TypeError: Cannot handle this data type: (1, 1, 3), <u2 for uint16 multi-channel images.

Root Cause

Pillow 12.0.0 removed support for creating multi-channel (RGB/RGBA) images from uint16 numpy arrays via fromarray(). The _fromarray_typemap no longer includes type keys like ((1, 1, 3), '<u2') and ((1, 1, 4), '<u2').

Changes

  • Modified create_thumbnail() in tensorflow_datasets/core/utils/image_utils.py
  • Added logic to detect uint16 images with 3 or 4 channels
  • Convert these images to uint8 by scaling from 16-bit range (0-65535) to 8-bit range (0-255) using division by 257
  • Single-channel uint16 images maintain original 'I;16' mode behavior

Testing

  • All ImageFeatureTest tests now pass with Pillow 12.0.0
  • Tested with uint16 images (1, 3, and 4 channels)
  • No regression in existing functionality

Compatibility

  • Maintains backward compatibility with older Pillow versions
  • Fixes forward compatibility with Pillow 12.0.0+

The old OneDrive API v1.0 URLs were returning HTTP 400 errors.
Updated to new OneDrive share links from the official Microsoft Research page.

Fixes tensorflow#11136
Pillow 12.0.0 removed support for creating multi-channel (RGB/RGBA)
images from uint16 numpy arrays via fromarray(). The _fromarray_typemap
no longer includes keys like ((1, 1, 3), '<u2') and ((1, 1, 4), '<u2').

This change converts uint16 RGB/RGBA images to uint8 in create_thumbnail()
by scaling from 16-bit (0-65535) to 8-bit (0-255) range before passing
to PIL's fromarray(). Single-channel uint16 images maintain original
behavior.

Fixes tensorflow#11148
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

Successfully merging this pull request may close these issues.

ImageFeatureTests are failing

1 participant