huggingface/transformers · error · ValueError
max_size = {max_size} must be strictly greater than the requ
Error message
max_size = {max_size} must be strictly greater than the requested size for the smaller edge size = {size} What it means
When resizing so the shortest edge becomes `size` while capping the longest at `max_size`, the cap only makes sense if max_size > size; otherwise every image would violate the cap immediately, so the helper raises ValueError. This mirrors torchvision Resize semantics.
Source
Thrown at src/transformers/image_transforms.py:303
return tuple(size)
elif len(size) == 1:
# Perform same logic as if size was an int
size = size[0]
else:
raise ValueError("size must have 1 or 2 elements if it is a list or tuple")
if default_to_square:
return (size, size)
height, width = get_image_size(input_image, input_data_format)
short, long = (width, height) if width <= height else (height, width)
requested_new_short = size
new_short, new_long = requested_new_short, int(requested_new_short * long / short)
if max_size is not None:
if max_size <= requested_new_short:
raise ValueError(
f"max_size = {max_size} must be strictly greater than the requested "
f"size for the smaller edge size = {size}"
)
if new_long > max_size:
new_short, new_long = int(max_size * new_short / new_long), max_size
return (new_long, new_short) if width <= height else (new_short, new_long)
def resize(
image: np.ndarray,
size: tuple[int, int],
resample: Optional["PILImageResampling"] = None,
reducing_gap: int | None = None,
data_format: ChannelDimension | None = None,
return_numpy: bool = True,
input_data_format: str | ChannelDimension | None = None,
) -> np.ndarray:View on GitHub (pinned to a597f97485)
Solutions
- Ensure max_size > size (e.g. size=800, max_size=1333).
- If you want a hard bound on both dims, use explicit (height, width) size instead of max_size.
- Add an assert in config code: assert max_size is None or max_size > size.
Example fix
# before size_dict = get_size_dict(800, max_size=800, default_to_square=False) # after size_dict = get_size_dict(800, max_size=1333, default_to_square=False)
Defensive patterns
Strategy: validation
Validate before calling
assert max_size is None or max_size > size, "max_size must be strictly greater than size"
Prevention
- Use established pairs like (800, 1333) from detection configs.
- Add a config-time assert when max_size and size are computed from variables.
When it happens
Trigger: get_resize_output_image_dims(img, size=800, max_size=800, default_to_square=False), or max_size < size such as size=1024/max_size=512. Note the comparison is strict: equal values also raise.
Common situations: Configs copied from detection models (800/1333) and then edited so max_size ends up <= size; programmatic size searches that set both from one variable; forgetting that equality is invalid.
Related errors
- Cannot specify both size as an int, with default_to_square=T
- Cannot specify both default_to_square=True and max_size
- Could not convert size input to size dict: {size}
- {param_name} must have one of the following set of keys: {VA
- size must have 1 or 2 elements if it is a list or tuple
AI-assisted analysis of huggingface/transformers@a597f97485 (2026-08-14).
Data as JSON: /api/errors/ac69afcb239168da.
Report an issue: GitHub.