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
Error "max_size = {max_size} must be strictly greater than the requested size for the smaller edge size = {size}" thrown in huggingface/transformers.
Source
Thrown at src/transformers/image_utils.py:851
size = tuple(size)
if isinstance(size, int) or len(size) == 1:
if default_to_square:
size = (size, size) if isinstance(size, int) else (size[0], size[0])
else:
width, height = image.size
# specified size only for the smallest edge
short, long = (width, height) if width <= height else (height, width)
requested_new_short = size if isinstance(size, int) else size[0]
if short == requested_new_short:
return image
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
size = (new_short, new_long) if width <= height else (new_long, new_short)
return image.resize(size, resample=resample)
def center_crop(self, image, size):
"""
Crops `image` to the given size using a center crop. Note that if the image is too small to be cropped to the
size given, it will be padded (so the returned result has the size asked).
Args:
image (`PIL.Image.Image` or `np.ndarray` or `torch.Tensor` of shape (n_channels, height, width) or (height, width, n_channels)):
The image to resize.View on GitHub (pinned to a597f97485)
Solutions
- Set `max_size` strictly greater than the requested smaller-edge size.
- Remove `max_size` to disable the cap.
When it happens
Trigger: Raised in resize size computation when max_size is not strictly greater than the requested shorter-edge size.
Common situations: size and max_size configured such that max_size <= size for the smaller edge in resize preprocessing.
AI-assisted analysis of huggingface/transformers@a597f97485 (2026-08-14).
Data as JSON: /api/errors/fe8cedf26e5c23db.
Report an issue: GitHub.