huggingface/transformers · error · ValueError

`crop_size` must be specified if `do_center_crop` is `True`.

Error message

`crop_size` must be specified if `do_center_crop` is `True`.

What it means

Error "`crop_size` must be specified if `do_center_crop` is `True`." thrown in huggingface/transformers.

Source

Thrown at src/transformers/image_utils.py:622

    if do_rescale and rescale_factor is None:
        raise ValueError("`rescale_factor` must be specified if `do_rescale` is `True`.")

    if do_pad and pad_size is None:
        # Processors pad images using different args depending on the model, so the below check is pointless
        # but we keep it for BC for now. TODO: remove in v5
        # Usually padding can be called with:
        #   - "pad_size/size" if we're padding to specific values
        #   - "size_divisor" if we're padding to any value divisible by X
        #   - "None" if we're padding to the maximum size image in batch
        raise ValueError(
            "Depending on the model, `size_divisor` or `pad_size` or `size` must be specified if `do_pad` is `True`."
        )

    if do_normalize and (image_mean is None or image_std is None):
        raise ValueError("`image_mean` and `image_std` must both be specified if `do_normalize` is `True`.")

    if do_center_crop and crop_size is None:
        raise ValueError("`crop_size` must be specified if `do_center_crop` is `True`.")

    if do_resize and not (size is not None and resample is not None):
        raise ValueError("`size` and `resample` must be specified if `do_resize` is `True`.")


class ImageFeatureExtractionMixin:
    """
    Mixin that contain utilities for preparing image features.
    """

    def _ensure_format_supported(self, image):
        if not isinstance(image, (PIL.Image.Image, np.ndarray)) and not is_torch_tensor(image):
            raise ValueError(
                f"Got type {type(image)} which is not supported, only `PIL.Image.Image`, `np.ndarray` and "
                "`torch.Tensor` are."
            )

    def to_pil_image(self, image, rescale=None):

View on GitHub (pinned to a597f97485)

Solutions

  1. Provide `crop_size` when `do_center_crop=True`.
  2. Set `do_center_crop=False` to skip center cropping.

When it happens

Trigger: Raised in image preprocess validation when do_center_crop=True but crop_size is not set.

Common situations: Requesting center cropping without defining crop_size in the image processor configuration.


AI-assisted analysis of huggingface/transformers@a597f97485 (2026-08-14). Data as JSON: /api/errors/d28ca72e1c7ca5f6. Report an issue: GitHub.