huggingface/transformers · error · ValueError
`image_mean` and `image_std` must both be specified if `do_n
Error message
`image_mean` and `image_std` must both be specified if `do_normalize` is `True`.
What it means
Error "`image_mean` and `image_std` must both be specified if `do_normalize` is `True`." thrown in huggingface/transformers.
Source
Thrown at src/transformers/image_utils.py:619
existing arguments when possible.
"""
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."View on GitHub (pinned to a597f97485)
Solutions
- Set both `image_mean` and `image_std` when `do_normalize=True`.
- Set `do_normalize=False` if normalization is not desired.
When it happens
Trigger: Raised in image preprocess validation when do_normalize=True but image_mean or image_std is None.
Common situations: Enabling normalization in a custom image processing call without supplying both mean and std.
AI-assisted analysis of huggingface/transformers@a597f97485 (2026-08-14).
Data as JSON: /api/errors/66f1e84b9ab31753.
Report an issue: GitHub.