{"record":{"id":"3d77efe4923db553","repo":"huggingface/transformers","slug":"size-must-have-1-or-2-elements-if-it-is-a-list-or","errorCode":null,"errorMessage":"size must have 1 or 2 elements if it is a list or tuple","messagePattern":"size must have 1 or 2 elements if it is a list or tuple","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/transformers/image_transforms.py","lineNumber":290,"sourceCode":"        max_size (`int`, *optional*):\n            The maximum allowed for the longer edge of the resized image: if the longer edge of the image is greater\n            than `max_size` after being resized according to `size`, then the image is resized again so that the longer\n            edge is equal to `max_size`. As a result, `size` might be overruled, i.e the smaller edge may be shorter\n            than `size`. Only used if `default_to_square` is `False`.\n        input_data_format (`ChannelDimension`, *optional*):\n            The channel dimension format of the input image. If unset, will use the inferred format from the input.\n\n    Returns:\n        `tuple`: The target (height, width) dimension of the output image after resizing.\n    \"\"\"\n    if isinstance(size, (tuple, list)):\n        if len(size) == 2:\n            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","sourceCodeStart":272,"sourceCodeEnd":308,"githubUrl":"https://github.com/huggingface/transformers/blob/a597f974857b3d92939971296bc0deb93d33d780/src/transformers/image_transforms.py#L272-L308","documentation":"In the resize-shape helper, a list/tuple `size` must reduce to a single int or a (h, w) pair; length 3+ (or empty beyond the handled cases) raises this ValueError. A 1-element list is treated as an int, 2 elements as (height, width).","triggerScenarios":"get_resize_output_image_dims(image, size=(224, 224, 3)) (accidentally including channels), size=[256, 256, 256], or size=[] style malformed iterables.","commonSituations":"Slicing arrays wrong so shape tuples include a channel dim, building size from image.shape, or config values written as 3-element lists.","solutions":["Pass size=(height, width) or a single int.","If size came from image.shape, take only spatial dims: h, w = image.shape[:2].","Validate len(size) in {1, 2} in your config loader before calling the processor."],"exampleFix":"# before\nsize = img.shape  # (H, W, 3)\nout = get_resize_output_image_dims(img, size=size, default_to_square=False)\n\n# after\nh, w = img.shape[:2]\nout = get_resize_output_image_dims(img, size=(h, w), default_to_square=False)","handlingStrategy":"validation","validationCode":"if isinstance(size, (tuple, list)):\n    assert 1 <= len(size) <= 2, f\"size must have 1 or 2 elements, got {len(size)}\"","typeGuard":"def is_valid_resize_size(s) -> bool:\n    return isinstance(s, int) or (isinstance(s, (tuple, list)) and len(s) in (1, 2))","tryCatchPattern":null,"preventionTips":["Never pass image.shape directly as size; slice to spatial dims only.","Freeze size constants in config as int or (h, w) pairs."],"tags":["image-processing","resize","validation","valueerror"],"backgroundTag":null,"analyzedSha":"a597f974857b3d92939971296bc0deb93d33d780","analyzedAt":"2026-08-14T18:24:08.354Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}