keras-team/keras · error · ValueError

Invalid value for argument `fill_mode`. Expected one of

Error message

Invalid value for argument `fill_mode`. Expected one of {set(MAP_COORDINATES_FILL_MODES.keys())}. Received: fill_mode={fill_mode}

What it means

Argument validation in `map_coordinates` (NumPy backend): `fill_mode` selects how out-of-bounds sample locations are handled and is matched against the MAPCOORDINATES_FILL_MODES table ('constant', 'nearest', 'reflect', etc.). A mode outside that table — including a spelling variant or a mode valid for `pad`/`resize` but not coordinate sampling — is rejected with the allowed set and the received value printed.

Solutions

  1. Use one of the supported fill modes, e.g. 'constant' with an explicit fill_value, or 'nearest'/'reflect'
  2. Normalize fill-mode strings from config to the exact supported spellings
  3. Default to 'constant' (fill_value=0.0) when the requested mode is unavailable
Defensive patterns

Strategy: validation

When it happens

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

Appendix: source

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

        raise ValueError(
            "First dim of `coordinates` must be the same as the rank of "
            "`inputs`. "
            f"Received inputs with shape: {inputs.shape} and coordinate "
            f"leading dim of {coordinates.shape[0]}"
        )
    if len(coordinates.shape) < 2:
        raise ValueError(
            "Invalid coordinates rank: expected at least rank 2."
            f" Received input with shape: {coordinates.shape}"
        )
    if fill_mode not in MAP_COORDINATES_FILL_MODES:
        raise ValueError(
            "Invalid value for argument `fill_mode`. Expected one of "
            f"{set(MAP_COORDINATES_FILL_MODES.keys())}. Received: "
            f"fill_mode={fill_mode}"
        )
    if order not in range(2):
        raise ValueError(
            "Invalid value for argument `order`. Expected one of "
            f"{[0, 1]}. Received: order={order}"
        )
    # SciPy's implementation of map_coordinates handles boundaries incorrectly,
    # unless mode='reflect'. For order=1, this only affects interpolation
    # outside the bounds of the original array.
    # https://github.com/scipy/scipy/issues/2640
    padding = [
        (
            max(-np.floor(c.min()).astype(int) + 1, 0),
            max(np.ceil(c.max()).astype(int) + 1 - size, 0),
        )
        for c, size in zip(coordinates, inputs.shape)
    ]
    shifted_coords = [c + p[0] for p, c in zip(padding, coordinates)]
    pad_mode = {
        "nearest": "edge",
        "mirror": "reflect",

View on GitHub (pinned to 7a34a03db6)