keras-team/keras · error · ValueError
Layer {self.__class__.__name__} does not take a `factor` arg
Error message
Layer {self.__class__.__name__} does not take a `factor` argument. Received: factor={factor} What it means
BaseImagePreprocessingLayer subclasses declare _USE_BASE_FACTOR=True only if augmentation strength is controlled by a factor (e.g. RandomContrast, Solarization). If a subclass that does not use factor (like AutoContrast) receives a non-None factor argument, the base __init__ raises this error to catch the misplaced configuration early.
Source
Thrown at keras/src/layers/preprocessing/image_preprocessing/base_image_preprocessing_layer.py:24
densify_bounding_boxes,
)
class BaseImagePreprocessingLayer(DataLayer):
_USE_BASE_FACTOR = True
_FACTOR_BOUNDS = (-1, 1)
def __init__(
self, factor=None, bounding_box_format=None, data_format=None, **kwargs
):
super().__init__(**kwargs)
self.bounding_box_format = bounding_box_format
self.data_format = backend_config.standardize_data_format(data_format)
if self._USE_BASE_FACTOR:
factor = factor or 0.0
self._set_factor(factor)
elif factor is not None:
raise ValueError(
f"Layer {self.__class__.__name__} does not take "
f"a `factor` argument. Received: factor={factor}"
)
def _set_factor(self, factor):
error_msg = (
"The `factor` argument should be a number "
"(or a list of two numbers) "
"in the range "
f"[{self._FACTOR_BOUNDS[0]}, {self._FACTOR_BOUNDS[1]}]. "
f"Received: factor={factor}"
)
if isinstance(factor, (tuple, list)):
if len(factor) != 2:
raise ValueError(error_msg)
if (
factor[0] > self._FACTOR_BOUNDS[1]
or factor[1] < self._FACTOR_BOUNDS[0]View on GitHub (pinned to 7a34a03db6)
Solutions
- Remove the factor argument from the constructor call of this layer.
- If you intended factor-based augmentation, use a layer that supports it (e.g. RandomContrast).
- Audit shared config dicts so layer-specific keys are not splatted via **kwargs into every layer.
Example fix
# before layer = keras.layers.AutoContrast(value_range=(0,255), factor=0.5) # after layer = keras.layers.AutoContrast(value_range=(0,255))
Defensive patterns
Strategy: validation
Validate before calling
import inspect
if "factor" not in inspect.signature(LayerClass.__init__).parameters:
kwargs.pop("factor", None) Prevention
- Do not splat a shared **aug_config into every layer; build per-layer kwargs explicitly.
- Check the layer signature when copying constructor calls between layers.
When it happens
Trigger: keras.layers.AutoContrast(factor=0.5) or any factor-free image layer constructed with a factor kwarg, often leaked from a copied config dict or **kwargs.
Common situations: Sharing a hyperparameter dict across multiple augmentation layers where only some accept factor; upgrading code where a layer signature changed and factor was removed.
Related errors
- {self._VALUE_RANGE_VALIDATION_ERROR}Received: value_range={v
- The `value_range` argument should be a list of two numbers.
- The `factor` argument should be a number (or a list of two n
- Invalid quantization mode. Expected one of {dtype_policies.Q
- Invalid value for argument `output_mode`. Expected one of {a
AI-assisted analysis of keras-team/keras@7a34a03db6 (2026-08-25).
Data as JSON: /api/errors/174101925076c1bc.
Report an issue: GitHub.