"...git@developer.sourcefind.cn:chenpangpang/transformers.git" did not exist on "2febd506149d039b51590f5dc7b45f0d8624819d"
Unverified Commit 3c4a8dca authored by Billy Cao's avatar Billy Cao Committed by GitHub
Browse files

[QoL fix] [Image processing] Add warning on assumption of channel dim and...


[QoL fix] [Image processing] Add warning on assumption of channel dim and avoid infering when inputs are PIL.Image (#31364)

* Add warning on assumption of channel dim
Use PIL info whenever possible to decide channel axis

* Fix ruff format

* Remove type checking
Improve warning message

* Update src/transformers/models/siglip/image_processing_siglip.py
Co-authored-by: default avataramyeroberts <22614925+amyeroberts@users.noreply.github.com>

* Update src/transformers/image_utils.py
Co-authored-by: default avataramyeroberts <22614925+amyeroberts@users.noreply.github.com>

* Update src/transformers/image_utils.py
Co-authored-by: default avataramyeroberts <22614925+amyeroberts@users.noreply.github.com>

---------
Co-authored-by: default avataramyeroberts <22614925+amyeroberts@users.noreply.github.com>
parent 348e2294
...@@ -234,7 +234,12 @@ def infer_channel_dimension_format( ...@@ -234,7 +234,12 @@ def infer_channel_dimension_format(
else: else:
raise ValueError(f"Unsupported number of image dimensions: {image.ndim}") raise ValueError(f"Unsupported number of image dimensions: {image.ndim}")
if image.shape[first_dim] in num_channels: if image.shape[first_dim] in num_channels and image.shape[last_dim] in num_channels:
logger.warning(
f"The channel dimension is ambiguous. Got image shape {image.shape}. Assuming channels are the first dimension."
)
return ChannelDimension.FIRST
elif image.shape[first_dim] in num_channels:
return ChannelDimension.FIRST return ChannelDimension.FIRST
elif image.shape[last_dim] in num_channels: elif image.shape[last_dim] in num_channels:
return ChannelDimension.LAST return ChannelDimension.LAST
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment