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_MODES}. What it means
RandomElasticTransform validates fill_mode in __init__ against _SUPPORTED_FILL_MODES. Fill mode controls how pixels mapped outside the input boundary are filled after the elastic warp; only the enumerated modes (e.g. 'reflect', 'wrap', 'constant', 'nearest') are implemented. Any other string raises NotImplementedError at construction.
Source
Thrown at keras/src/layers/preprocessing/image_preprocessing/random_elastic_transform.py:113
):
super().__init__(data_format=data_format, **kwargs)
self._set_factor(factor)
self.scale = self._set_factor_by_name(scale, "scale")
self.interpolation = interpolation
self.fill_mode = fill_mode
self.fill_value = fill_value
self.value_range = value_range
self.seed = seed
self.generator = SeedGenerator(seed)
if interpolation not in self._SUPPORTED_INTERPOLATION:
raise NotImplementedError(
f"Unknown `interpolation` {interpolation}. Expected of one "
f"{self._SUPPORTED_INTERPOLATION}."
)
if fill_mode not in self._SUPPORTED_FILL_MODES:
raise NotImplementedError(
f"Unknown `fill_mode` {fill_mode}. Expected of one "
f"{self._SUPPORTED_FILL_MODES}."
)
if self.data_format == "channels_first":
self.height_axis = -2
self.width_axis = -1
self.channel_axis = -3
else:
self.height_axis = -3
self.width_axis = -2
self.channel_axis = -1
def _set_factor_by_name(self, factor, name):
error_msg = (
f"The `{name}` argument should be a number "
"(or a list of two numbers) "
"in the range "View on GitHub (pinned to 7a34a03db6)
Solutions
- Use an exact string from RandomElasticTransform._SUPPORTED_FILL_MODES, e.g. 'constant' when pairing it with fill_value
- Check the accepted set: print(layers.RandomElasticTransform._SUPPORTED_FILL_MODES)
- Map your existing config vocabulary: OpenCV 'replicate' -> 'nearest', 'edge' -> 'nearest'
Example fix
# before layers.RandomElasticTransform(fill_mode="replicate") # after layers.RandomElasticTransform(fill_mode="nearest")
Defensive patterns
Strategy: validation
Validate before calling
from keras.src.layers.preprocessing.image_preprocessing.random_elastic_transform import RandomElasticTransform assert fill_mode in RandomElasticTransform._SUPPORTED_FILL_MODES
Type guard
def is_valid_fill_mode(v: str) -> bool:
return v in {"reflect", "wrap", "constant", "nearest"} Try / catch
try:
layer = RandomElasticTransform(fill_mode=mode)
except NotImplementedError as e:
raise ValueError(f"bad fill_mode {mode!r}: {e}") from e Prevention
- Translate fill-mode names when porting from OpenCV/Pillow vocabulary
- Validate strings against the class constant before constructing
When it happens
Trigger: layers.RandomElasticTransform(fill_mode='replicate') or fill_mode='edge' (Pillow/OpenCV vocabulary), fill_mode='black', or a typo like 'constnat'.
Common situations: Porting augmentation configs from albumentations, torchvision, or OpenCV, whose fill-mode names ('replicate', 'edge') differ from Keras's; assuming OpenCV's cv2.BORDER_* constants work unchanged.
Related errors
- Unknown `interpolation` {interpolation}. Expected of one {se
- The `{name}` argument should be a number (or a list of two n
- The `{name}` argument should be a number (or a list of two n
- The `fill_value` argument should be a number (or a list of t
- The `{name}` argument should be a number (or a list of two n
AI-assisted analysis of keras-team/keras@7a34a03db6 (2026-08-25).
Data as JSON: /api/errors/22e03610cf363b87.
Report an issue: GitHub.