huggingface/transformers · error · ValueError
Size must contain 'height' and 'width' keys, or 'max_height'
Error message
Size must contain 'height' and 'width' keys, or 'max_height' and 'max_width', or 'shortest_edge' key. Got {size}. What it means
Error "Size must contain 'height' and 'width' keys, or 'max_height' and 'max_width', or 'shortest_edge' key. Got {size}." thrown in huggingface/transformers.
Source
Thrown at src/transformers/image_processing_backends.py:249
if size.shortest_edge and size.longest_edge:
new_size = get_size_with_aspect_ratio(
image.size()[-2:],
size.shortest_edge,
size.longest_edge,
)
elif size.shortest_edge:
new_size = get_resize_output_image_size(
image,
size=size.shortest_edge,
default_to_square=False,
input_data_format=ChannelDimension.FIRST,
)
elif size.max_height and size.max_width:
new_size = get_image_size_for_max_height_width(image.size()[-2:], size.max_height, size.max_width)
elif size.height and size.width:
new_size = (size.height, size.width)
else:
raise ValueError(
"Size must contain 'height' and 'width' keys, or 'max_height' and 'max_width', or 'shortest_edge' key. Got"
f" {size}."
)
# Workaround for torch.compile issue with uint8 on AMD GPUs
if is_torchdynamo_compiling() and is_rocm_platform():
return self._compile_friendly_resize(image, new_size, interpolation, antialias)
return tvF.resize(image, new_size, interpolation=interpolation, antialias=antialias)
@staticmethod
def _compile_friendly_resize(
image: "torch.Tensor",
new_size: tuple[int, int],
interpolation: Optional["tvF.InterpolationMode"] = None,
antialias: bool = True,
) -> "torch.Tensor":
"""A wrapper around tvF.resize for torch.compile compatibility with uint8 tensors."""
if image.dtype == torch.uint8:View on GitHub (pinned to a597f97485)
Solutions
- Provide size with 'height'/'width', 'max_height'/'max_width', or 'shortest_edge' keys.
- Use `get_size_dict` to normalize the size argument.
When it happens
Trigger: Raised in image resize preprocessing when the size dict lacks a recognized key combination.
Common situations: size dict without ('height','width'), ('max_height','max_width'), or 'shortest_edge' keys passed to a resize backend.
AI-assisted analysis of huggingface/transformers@a597f97485 (2026-08-14).
Data as JSON: /api/errors/9f838699bfb105a5.
Report an issue: GitHub.