{"record":{"id":"eeab230a1c185242","repo":"huggingface/transformers","slug":"padding-dimensions-are-negative-please-make-sure-eeab23","errorCode":null,"errorMessage":"Padding dimensions are negative. Please make sure that the `pad_size` is larger than the image size. Got pad_size=({target_height}, {target_width}), image_size=({height}, {width}).","messagePattern":"Padding dimensions are negative\\. Please make sure that the `pad_size` is larger than the image size\\. Got pad_size=\\((.+?), (.+?)\\), image_size=\\((.+?), (.+?)\\)\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/transformers/image_processing_backends.py","lineNumber":496,"sourceCode":"    ) -> tuple[list[np.ndarray], list[np.ndarray]] | list[np.ndarray]:\n        \"\"\"Pad images to specified size using NumPy.\"\"\"\n        if pad_size is not None:\n            if not (pad_size.height and pad_size.width):\n                raise ValueError(f\"Pad size must contain 'height' and 'width' keys only. Got pad_size={pad_size}.\")\n            target_height, target_width = pad_size.height, pad_size.width\n        else:\n            target_height, target_width = get_max_height_width(images)\n\n        processed_images = []\n        processed_masks = []\n\n        for image in images:\n            height, width = get_image_size(image, channel_dim=ChannelDimension.FIRST)\n            padding_height = target_height - height\n            padding_width = target_width - width\n\n            if padding_height < 0 or padding_width < 0:\n                raise ValueError(\n                    f\"Padding dimensions are negative. Please make sure that the `pad_size` is larger than the \"\n                    f\"image size. Got pad_size=({target_height}, {target_width}), image_size=({height}, {width}).\"\n                )\n\n            if height != target_height or width != target_width:\n                # Pad format: ((before_1, after_1), (before_2, after_2), ...)\n                # For CHW format: ((0, 0), (0, padding_height), (0, padding_width))\n                pad_width = ((0, 0), (0, padding_height), (0, padding_width))\n                if padding_mode == \"constant\":\n                    image = np.pad(image, pad_width, mode=\"constant\", constant_values=fill_value)\n                else:\n                    image = np.pad(image, pad_width, mode=padding_mode)\n\n            processed_images.append(image)\n\n            if return_mask:\n                mask = np.zeros((target_height, target_width), dtype=np.int64)\n                mask[:height, :width] = 1","sourceCodeStart":478,"sourceCodeEnd":514,"githubUrl":"https://github.com/huggingface/transformers/blob/a597f974857b3d92939971296bc0deb93d33d780/src/transformers/image_processing_backends.py#L478-L514","documentation":"Error \"Padding dimensions are negative. Please make sure that the `pad_size` is larger than the image size. Got pad_size=({target_height}, {target_width}), image_size=({height}, {width}).\" thrown in huggingface/transformers.","triggerScenarios":"Raised in image padding when computed target height/width are below the image height/width, producing negative padding.","commonSituations":"Pad-to-target operations where the target size is smaller than the input image, e.g. after an unexpected upscale.","solutions":["Make target padding dimensions at least as large as the image dimensions.","Swap or recompute target_height/target_width if they were computed incorrectly."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"a597f974857b3d92939971296bc0deb93d33d780","analyzedAt":"2026-08-14T18:24:08.354Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}