[Bugfix] Handle HWC images in ImageProcessorItems.get_image_size (#45057)

Signed-off-by: YellowFoxH4XOR <yellowfoxh4xor@gmail.com>
Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
Akshat katiyar
2026-06-10 05:35:50 +00:00
committed by GitHub
co-authored by Claude
parent 6aec99f030
commit 47930b59ca
2 changed files with 58 additions and 1 deletions
+7 -1
View File
@@ -334,7 +334,13 @@ class ImageProcessorItems(ProcessorBatchItems[HfImageItem | None]):
if isinstance(image, PILImage.Image):
return ImageSize(*image.size)
if isinstance(image, (np.ndarray, torch.Tensor)):
_, h, w = image.shape
if image.ndim == 3 and image.shape[-1] in (1, 3, 4):
# HWC format (e.g. from np.array(PIL.Image)).
# PIL images are always channels-last.
h, w = image.shape[0], image.shape[1]
else:
# CHW format (standard PyTorch / numpy convention).
_, h, w = image.shape
return ImageSize(w, h)
assert_never(image)