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

[QoL fix] [Image processing] Add warning on assumption of channel dim #31364

Merged
merged 6 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/transformers/image_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import base64
import os
import warnings
aliencaocao marked this conversation as resolved.
Show resolved Hide resolved
from io import BytesIO
from typing import TYPE_CHECKING, Dict, Iterable, List, Optional, Tuple, Union

Expand Down Expand Up @@ -202,7 +203,12 @@ def infer_channel_dimension_format(
else:
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:
warnings.warn(
f"The channel dimension is ambiguous. Got image shape {image.shape}. Assuming channels are the first dimension. Please specify with input_data_format if this is incorrect."
)
aliencaocao marked this conversation as resolved.
Show resolved Hide resolved
return ChannelDimension.FIRST
elif image.shape[first_dim] in num_channels:
return ChannelDimension.FIRST
elif image.shape[last_dim] in num_channels:
return ChannelDimension.LAST
Expand Down
1 change: 1 addition & 0 deletions src/transformers/models/siglip/image_processing_siglip.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ def preprocess(
size=size,
resample=resample,
)

aliencaocao marked this conversation as resolved.
Show resolved Hide resolved
# All transformations expect numpy arrays.
images = [to_numpy_array(image) for image in images]

Expand Down