keras-team/keras · error · ValueError

Invalid value for argument `fill_mode`. Only `'constant'`…

Error message

Invalid value for argument `fill_mode`. Only `'constant'` is supported. Received: fill_mode={fill_mode}

What it means

Restriction guard in `resize` (NumPy backend): unlike the TensorFlow implementation, the NumPy resize path only implements padding with a constant fill value. If `fill_mode` is anything other than 'constant' (e.g. 'reflect' or 'nearest'), the guard rejects the request instead of silently substituting the default behavior; the fill value itself is still controlled by `fill_value`.

Solutions

  1. Keep fill_mode='constant' (the default) and set the desired pad color via fill_value
  2. Pre-pad the images manually with keras.ops.pad using the desired non-constant mode before resizing with pad_to_aspect_ratio
  3. Use the TensorFlow backend if non-constant fill modes during aspect-ratio padding are required
Defensive patterns

Strategy: fallback

When it happens

Trigger: Thrown at keras/src/backend/numpy/ops/image.py:184 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of keras-team/keras@7a34a03db6 (2026-08-25). Data as JSON: /api/errors/d95eb948d0f34fba. Report an issue: GitHub.

Appendix: source

Thrown at keras/src/backend/numpy/ops/image.py:184

def resize(
    images,
    size,
    interpolation="bilinear",
    antialias=False,
    crop_to_aspect_ratio=False,
    pad_to_aspect_ratio=False,
    fill_mode="constant",
    fill_value=0.0,
    data_format=None,
):
    data_format = standardize_data_format(data_format)
    if interpolation not in RESIZE_INTERPOLATIONS:
        raise ValueError(
            "Invalid value for argument `interpolation`. Expected of one "
            f"{RESIZE_INTERPOLATIONS}. Received: interpolation={interpolation}"
        )
    if fill_mode != "constant":
        raise ValueError(
            "Invalid value for argument `fill_mode`. Only `'constant'` "
            f"is supported. Received: fill_mode={fill_mode}"
        )
    if pad_to_aspect_ratio and crop_to_aspect_ratio:
        raise ValueError(
            "Only one of `pad_to_aspect_ratio` & `crop_to_aspect_ratio` "
            "can be `True`."
        )
    if not len(size) == 2:
        raise ValueError(
            "Argument `size` must be a tuple of two elements "
            f"(height, width). Received: size={size}"
        )
    size = tuple(size)
    target_height, target_width = size
    if len(images.shape) == 4:
        if data_format == "channels_last":
            size = (images.shape[0],) + size + (images.shape[-1],)

View on GitHub (pinned to 7a34a03db6)