{"record":{"id":"d28ca72e1c7ca5f6","repo":"huggingface/transformers","slug":"crop-size-must-be-specified-if-do-center-crop","errorCode":null,"errorMessage":"`crop_size` must be specified if `do_center_crop` is `True`.","messagePattern":"`crop_size` must be specified if `do_center_crop` is `True`\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/transformers/image_utils.py","lineNumber":622,"sourceCode":"    if do_rescale and rescale_factor is None:\n        raise ValueError(\"`rescale_factor` must be specified if `do_rescale` is `True`.\")\n\n    if do_pad and pad_size is None:\n        # Processors pad images using different args depending on the model, so the below check is pointless\n        # but we keep it for BC for now. TODO: remove in v5\n        # Usually padding can be called with:\n        #   - \"pad_size/size\" if we're padding to specific values\n        #   - \"size_divisor\" if we're padding to any value divisible by X\n        #   - \"None\" if we're padding to the maximum size image in batch\n        raise ValueError(\n            \"Depending on the model, `size_divisor` or `pad_size` or `size` must be specified if `do_pad` is `True`.\"\n        )\n\n    if do_normalize and (image_mean is None or image_std is None):\n        raise ValueError(\"`image_mean` and `image_std` must both be specified if `do_normalize` is `True`.\")\n\n    if do_center_crop and crop_size is None:\n        raise ValueError(\"`crop_size` must be specified if `do_center_crop` is `True`.\")\n\n    if do_resize and not (size is not None and resample is not None):\n        raise ValueError(\"`size` and `resample` must be specified if `do_resize` is `True`.\")\n\n\nclass ImageFeatureExtractionMixin:\n    \"\"\"\n    Mixin that contain utilities for preparing image features.\n    \"\"\"\n\n    def _ensure_format_supported(self, image):\n        if not isinstance(image, (PIL.Image.Image, np.ndarray)) and not is_torch_tensor(image):\n            raise ValueError(\n                f\"Got type {type(image)} which is not supported, only `PIL.Image.Image`, `np.ndarray` and \"\n                \"`torch.Tensor` are.\"\n            )\n\n    def to_pil_image(self, image, rescale=None):","sourceCodeStart":604,"sourceCodeEnd":640,"githubUrl":"https://github.com/huggingface/transformers/blob/a597f974857b3d92939971296bc0deb93d33d780/src/transformers/image_utils.py#L604-L640","documentation":"Error \"`crop_size` must be specified if `do_center_crop` is `True`.\" thrown in huggingface/transformers.","triggerScenarios":"Raised in image preprocess validation when do_center_crop=True but crop_size is not set.","commonSituations":"Requesting center cropping without defining crop_size in the image processor configuration.","solutions":["Provide `crop_size` when `do_center_crop=True`.","Set `do_center_crop=False` to skip center cropping."],"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"}