{"record":{"id":"296e752602189058","repo":"huggingface/transformers","slug":"size-must-have-2-elements","errorCode":null,"errorMessage":"size must have 2 elements","messagePattern":"size must have 2 elements","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/transformers/image_transforms.py","lineNumber":351,"sourceCode":"            Apply optimization by resizing the image in two steps. The bigger `reducing_gap`, the closer the result to\n            the fair resampling. See corresponding Pillow documentation for more details.\n        data_format (`ChannelDimension`, *optional*):\n            The channel dimension format of the output image. If unset, will use the inferred format from the input.\n        return_numpy (`bool`, *optional*, defaults to `True`):\n            Whether or not to return the resized image as a numpy array. If False a `PIL.Image.Image` object is\n            returned.\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        `np.ndarray`: The resized image.\n    \"\"\"\n    requires_backends(resize, [\"vision\"])\n\n    resample = resample if resample is not None else PILImageResampling.BILINEAR\n\n    if not len(size) == 2:\n        raise ValueError(\"size must have 2 elements\")\n\n    # For all transformations, we want to keep the same data format as the input image unless otherwise specified.\n    # The resized image from PIL will always have channels last, so find the input format first.\n    if input_data_format is None:\n        input_data_format = infer_channel_dimension_format(image)\n    data_format = input_data_format if data_format is None else data_format\n\n    # To maintain backwards compatibility with the resizing done in previous image feature extractors, we use\n    # the pillow library to resize the image and then convert back to numpy\n    do_rescale = False\n    if not isinstance(image, PIL.Image.Image):\n        do_rescale = _rescale_for_pil_conversion(image)\n        image = to_pil_image(image, do_rescale=do_rescale, input_data_format=input_data_format)\n    height, width = size\n    # PIL images are in the format (width, height)\n    resized_image = image.resize((width, height), resample=resample, reducing_gap=reducing_gap)\n\n    if return_numpy:","sourceCodeStart":333,"sourceCodeEnd":369,"githubUrl":"https://github.com/huggingface/transformers/blob/a597f974857b3d92939971296bc0deb93d33d780/src/transformers/image_transforms.py#L333-L369","documentation":"The resize function requires exactly two elements (height, width) in `size`; len != 2 raises ValueError before any PIL work starts. Unlike the dims helper, a 1-element list is not auto-expanded here.","triggerScenarios":"resize(image, size=(224,)), resize(image, size=224) (an int has no len -> TypeError/len failure), or size=(224, 224, 3) including channels.","commonSituations":"Passing an int size directly to resize instead of going through the size-dict/processor layer, or forwarding a 3-D shape tuple.","solutions":["Always pass a 2-tuple: resize(image, size=(224, 224)).","For int semantics, expand first: (s, s).","Prefer the image processor's preprocess/__call__ which normalizes size for you."],"exampleFix":"# before\nimg = resize(img, size=224)  # not a 2-tuple\n\n# after\nimg = resize(img, size=(224, 224))","handlingStrategy":"validation","validationCode":"if not (isinstance(size, (tuple, list)) and len(size) == 2):\n    size = (size, size) if isinstance(size, int) else tuple(size)","typeGuard":"def is_hw_pair(s) -> bool:\n    return isinstance(s, (tuple, list)) and len(s) == 2","tryCatchPattern":null,"preventionTips":["Expand int sizes to (s, s) at your call sites once, in a helper.","Prefer processor.preprocess over raw resize for user-supplied sizes."],"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"}