{"record":{"id":"001e501bb0f769a3","repo":"huggingface/transformers","slug":"the-size-dictionary-must-have-keys-height-and-w","errorCode":null,"errorMessage":"The size dictionary must have keys 'height' and 'width'. Got {size.keys()}","messagePattern":"The size dictionary must have keys 'height' and 'width'\\. Got (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/transformers/image_processing_backends.py","lineNumber":347,"sourceCode":"            rescale_factor=rescale_factor,\n            device=images.device,\n        )\n        if do_normalize:\n            images = self.normalize(images.to(dtype=torch.float32), image_mean, image_std)\n        elif do_rescale:\n            images = self.rescale(images, rescale_factor)\n\n        return images\n\n    def center_crop(\n        self,\n        image: \"torch.Tensor\",\n        size: SizeDict,\n        **kwargs,\n    ) -> \"torch.Tensor\":\n        \"\"\"Center crop an image using Torchvision.\"\"\"\n        if size.height is None or size.width is None:\n            raise ValueError(f\"The size dictionary must have keys 'height' and 'width'. Got {size.keys()}\")\n        image_height, image_width = image.shape[-2:]\n        crop_height, crop_width = size.height, size.width\n\n        if crop_width > image_width or crop_height > image_height:\n            padding_ltrb = [\n                (crop_width - image_width) // 2 if crop_width > image_width else 0,\n                (crop_height - image_height) // 2 if crop_height > image_height else 0,\n                (crop_width - image_width + 1) // 2 if crop_width > image_width else 0,\n                (crop_height - image_height + 1) // 2 if crop_height > image_height else 0,\n            ]\n            image = tvF.pad(image, padding_ltrb, fill=0)\n            image_height, image_width = image.shape[-2:]\n            if crop_width == image_width and crop_height == image_height:\n                return image\n\n        crop_top = int((image_height - crop_height) / 2.0)\n        crop_left = int((image_width - crop_width) / 2.0)\n        return tvF.crop(image, crop_top, crop_left, crop_height, crop_width)","sourceCodeStart":329,"sourceCodeEnd":365,"githubUrl":"https://github.com/huggingface/transformers/blob/a597f974857b3d92939971296bc0deb93d33d780/src/transformers/image_processing_backends.py#L329-L365","documentation":"Error \"The size dictionary must have keys 'height' and 'width'. Got {size.keys()}\" thrown in huggingface/transformers.","triggerScenarios":"Raised in image preprocessing when a size dict is missing required 'height' or 'width' keys.","commonSituations":"Passing size={'shortest_edge': ...} or partial dicts where the code path strictly requires height and width.","solutions":["Pass size as a dict containing both 'height' and 'width' keys.","Pass an int and set default_to_square=True if a square size is intended."],"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"}