huggingface/transformers · error · ValueError

`size` and `resample` must be specified if `do_resize` is `T

Error message

`size` and `resample` must be specified if `do_resize` is `True`.

What it means

Error "`size` and `resample` must be specified if `do_resize` is `True`." thrown in huggingface/transformers.

Source

Thrown at src/transformers/image_utils.py:625

    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):
        """
        Converts `image` to a PIL Image. Optionally rescales it and puts the channel dimension back as the last axis if
        needed.

View on GitHub (pinned to a597f97485)

Solutions

  1. Provide both `size` and `resample` when `do_resize=True`.
  2. Set `do_resize=False` to skip resizing.

When it happens

Trigger: Raised in image preprocess validation when do_resize=True but size or resample is not set.

Common situations: Enabling resize with a missing size dict or missing resample filter in the preprocessing config.


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