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 RandomZoom's constructor when `fill_mode` is not one of "constant", "reflect", "wrap", "nearest". It controls how the newly exposed border pixels are filled after zooming out.

Source

Thrown at keras/src/layers/preprocessing/image_preprocessing/random_zoom.py:130

        fill_mode="reflect",
        interpolation="bilinear",
        seed=None,
        fill_value=0.0,
        data_format=None,
        **kwargs,
    ):
        super().__init__(**kwargs)
        self.height_factor = height_factor
        self.height_lower, self.height_upper = self._set_factor(
            height_factor, "height_factor"
        )
        self.width_factor = width_factor
        if width_factor is not None:
            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.data_format = backend.standardize_data_format(data_format)
        self.supports_jit = False

    def _set_factor(self, factor, factor_name):

View on GitHub (pinned to 7a34a03db6)

Solutions

  1. Use one of "constant", "reflect", "wrap", "nearest"
  2. Use "constant" with fill_value for a fixed color

Example fix

// before
layer = RandomZoom(0.2, fill_mode="replicate")
// after
layer = RandomZoom(0.2, fill_mode="reflect")
Defensive patterns

Strategy: validation

Validate before calling

assert fill_mode in {"constant", "reflect", "wrap", "nearest"}, 'unsupported fill_mode'

Type guard

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

Try / catch

try:
    layer = RandomZoom(0.2, fill_mode=fill_mode)
except NotImplementedError:
    layer = RandomZoom(0.2, fill_mode="reflect")

Prevention

When it happens

Trigger: Calling RandomZoom(0.2, fill_mode="replicate") or any string outside the supported set.

Common situations: Porting augmentation configs from torchvision/OpenCV with their fill-mode names; typos in config files.

Related errors


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