keras-team/keras · error · NotImplementedError

Unknown `fill_mode` {fill_mode}. Expected of one {self._SUPP

Error message

Unknown `fill_mode` {fill_mode}. Expected of one {self._SUPPORTED_FILL_MODE}.

What it means

Raised by RandomTranslation's constructor when `fill_mode` is not one of the supported modes ("constant", "reflect", "wrap", "nearest"). The mode controls how pixels emptied by the translation are filled.

Source

Thrown at keras/src/layers/preprocessing/image_preprocessing/random_translation.py:129

        fill_mode="reflect",
        interpolation="bilinear",
        seed=None,
        fill_value=0.0,
        data_format=None,
        **kwargs,
    ):
        super().__init__(data_format=data_format, **kwargs)
        self.height_factor = height_factor
        self.height_lower, self.height_upper = self._set_factor(
            height_factor, "height_factor"
        )
        self.width_factor = width_factor
        self.width_lower, self.width_upper = self._set_factor(
            width_factor, "width_factor"
        )

        if fill_mode not in self._SUPPORTED_FILL_MODE:
            raise NotImplementedError(
                f"Unknown `fill_mode` {fill_mode}. Expected of one "
                f"{self._SUPPORTED_FILL_MODE}."
            )
        if interpolation not in self._SUPPORTED_INTERPOLATION:
            raise NotImplementedError(
                f"Unknown `interpolation` {interpolation}. Expected of one "
                f"{self._SUPPORTED_INTERPOLATION}."
            )

        self.fill_mode = fill_mode
        self.fill_value = fill_value
        self.interpolation = interpolation
        self.seed = seed
        self.generator = SeedGenerator(seed)
        self.supports_jit = False

    def _set_factor(self, factor, factor_name):
        if isinstance(factor, (tuple, list)):

View on GitHub (pinned to 7a34a03db6)

Solutions

  1. Use one of "constant", "reflect", "wrap", "nearest"
  2. If porting from torchvision's "replicate", use "nearest" or "wrap" as the closest Keras equivalent
  3. For a solid fill color, use fill_mode="constant" with fill_value

Example fix

// before
layer = RandomTranslation(0.1, 0.1, fill_mode="replicate")
// after
layer = RandomTranslation(0.1, 0.1, fill_mode="nearest")
Defensive patterns

Strategy: validation

Validate before calling

SUPPORTED_FILL = {"constant", "reflect", "wrap", "nearest"}
assert fill_mode in SUPPORTED_FILL, f"fill_mode must be one of {SUPPORTED_FILL}"

Type guard

def is_valid_fill_mode(m):
    return m in {"constant", "reflect", "wrap", "nearest"}

Try / catch

try:
    layer = RandomTranslation(0.1, 0.1, fill_mode=fill_mode)
except NotImplementedError as e:
    raise ValueError(f"Unsupported fill_mode {fill_mode!r}; valid: constant, reflect, wrap, nearest") from e

Prevention

When it happens

Trigger: Calling RandomTranslation(height_factor=0.1, fill_mode="mirror") or fill_mode="replicate" — strings accepted by other frameworks but not Keras.

Common situations: Porting augmentation configs from torchvision ("reflect", "replicate") or OpenCV (cv2.BORDER_*); misspelling a supported mode.

Related errors


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