{"record":{"id":"ac69afcb239168da","repo":"huggingface/transformers","slug":"max-size-max-size-must-be-strictly-greater-tha","errorCode":null,"errorMessage":"max_size = {max_size} must be strictly greater than the requested size for the smaller edge size = {size}","messagePattern":"max_size = (.+?) must be strictly greater than the requested size for the smaller edge size = (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/transformers/image_transforms.py","lineNumber":303,"sourceCode":"            return tuple(size)\n        elif len(size) == 1:\n            # Perform same logic as if size was an int\n            size = size[0]\n        else:\n            raise ValueError(\"size must have 1 or 2 elements if it is a list or tuple\")\n\n    if default_to_square:\n        return (size, size)\n\n    height, width = get_image_size(input_image, input_data_format)\n    short, long = (width, height) if width <= height else (height, width)\n    requested_new_short = size\n\n    new_short, new_long = requested_new_short, int(requested_new_short * long / short)\n\n    if max_size is not None:\n        if max_size <= requested_new_short:\n            raise ValueError(\n                f\"max_size = {max_size} must be strictly greater than the requested \"\n                f\"size for the smaller edge size = {size}\"\n            )\n        if new_long > max_size:\n            new_short, new_long = int(max_size * new_short / new_long), max_size\n\n    return (new_long, new_short) if width <= height else (new_short, new_long)\n\n\ndef resize(\n    image: np.ndarray,\n    size: tuple[int, int],\n    resample: Optional[\"PILImageResampling\"] = None,\n    reducing_gap: int | None = None,\n    data_format: ChannelDimension | None = None,\n    return_numpy: bool = True,\n    input_data_format: str | ChannelDimension | None = None,\n) -> np.ndarray:","sourceCodeStart":285,"sourceCodeEnd":321,"githubUrl":"https://github.com/huggingface/transformers/blob/a597f974857b3d92939971296bc0deb93d33d780/src/transformers/image_transforms.py#L285-L321","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"# before\nsize_dict = get_size_dict(800, max_size=800, default_to_square=False)\n\n# after\nsize_dict = get_size_dict(800, max_size=1333, default_to_square=False)","handlingStrategy":"validation","validationCode":"assert max_size is None or max_size > size, \"max_size must be strictly greater than size\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use established pairs like (800, 1333) from detection configs.","Add a config-time assert when max_size and size are computed from variables."],"tags":["image-processing","resize","config","valueerror"],"backgroundTag":null,"analyzedSha":"a597f974857b3d92939971296bc0deb93d33d780","analyzedAt":"2026-08-14T18:24:08.354Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}