keras-team/keras · error · ValueError

Invalid value for argument `fill_mode`. Expected of one

Error message

Invalid value for argument `fill_mode`. Expected of one {AFFINE_TRANSFORM_FILL_MODES}. Received: fill_mode={fill_mode}

What it means

Argument validation in `affine_transform` (NumPy backend): after the interpolation check, `fill_mode` (how out-of-bounds pixels are filled when warping) is matched against the AFFINE_TRANSFORM_FILL_MODES set ('constant', 'reflect', 'wrap', 'nearest', etc.). Any mode outside that set — including modes valid for `resize` but not for affine warping — triggers this error listing the allowed modes and the received value.

Solutions

  1. Use one of the printed fill modes, e.g. 'constant' or 'reflect'
  2. Verify the value is not confused with resize's fill modes or scipy's naming
  3. Default to 'constant' with an explicit fill_value when the requested mode is unsupported
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at keras/src/backend/numpy/ops/image.py:566 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/e7afb439124f9c62. Report an issue: GitHub.

Appendix: source

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


def affine_transform(
    images,
    transform,
    interpolation="bilinear",
    fill_mode="constant",
    fill_value=0,
    data_format=None,
):
    data_format = standardize_data_format(data_format)
    if interpolation not in AFFINE_TRANSFORM_INTERPOLATIONS.keys():
        raise ValueError(
            "Invalid value for argument `interpolation`. Expected of one "
            f"{set(AFFINE_TRANSFORM_INTERPOLATIONS.keys())}. Received: "
            f"interpolation={interpolation}"
        )
    if fill_mode not in AFFINE_TRANSFORM_FILL_MODES:
        raise ValueError(
            "Invalid value for argument `fill_mode`. Expected of one "
            f"{AFFINE_TRANSFORM_FILL_MODES}. Received: fill_mode={fill_mode}"
        )

    images = convert_to_tensor(images)
    transform = convert_to_tensor(transform)

    if len(images.shape) not in (3, 4):
        raise ValueError(
            "Invalid images rank: expected rank 3 (single image) "
            "or rank 4 (batch of images). Received input with shape: "
            f"images.shape={images.shape}"
        )
    if len(transform.shape) not in (1, 2):
        raise ValueError(
            "Invalid transform rank: expected rank 1 (single transform) "
            "or rank 2 (batch of transforms). Received input with shape: "
            f"transform.shape={transform.shape}"

View on GitHub (pinned to 7a34a03db6)