keras-team/keras · error · ValueError
Cannot adapt a Discretization layer that has been initialize
Error message
Cannot adapt a Discretization layer that has been initialized with `bin_boundaries`, use `num_bins` instead.
What it means
Error "Cannot adapt a Discretization layer that has been initialized with `bin_boundaries`, use `num_bins` instead." thrown in keras-team/keras.
Source
Thrown at keras/src/layers/preprocessing/discretization.py:187
input dataset. The number of quantiles can be controlled via the
`num_bins` argument, and the error tolerance for quantile boundaries can
be controlled via the `epsilon` argument.
Arguments:
data: The data to train on. It can be passed either as a
batched `tf.data.Dataset`, a Grain dataset, as a NumPy
array, or as any iterable of batches (e.g. a list of
arrays or a generator yielding batches).
steps: Integer or `None`.
Total number of steps (batches of samples) to process.
If `data` is a `tf.data.Dataset`, and `steps` is `None`,
`adapt()` will run until the input dataset is exhausted.
When passing an infinitely
repeating dataset, you must specify the `steps` argument. This
argument is not supported with array inputs or list inputs.
"""
if self.num_bins is None:
raise ValueError(
"Cannot adapt a Discretization layer that has been initialized "
"with `bin_boundaries`, use `num_bins` instead."
)
self.reset_state()
if isinstance(data, tf.data.Dataset):
if steps is None and hasattr(data, "cardinality"):
cardinality = data.cardinality()
if cardinality.numpy() not in (
tf.data.UNKNOWN_CARDINALITY,
tf.data.INFINITE_CARDINALITY,
):
steps = int(cardinality.numpy())
progbar = Progbar(target=steps, unit_name="step")
if steps is not None:
data = data.take(steps)
for i, batch in enumerate(data):
self.update_state(batch)View on GitHub (pinned to 7a34a03db6)
When it happens
Trigger: Thrown at keras/src/layers/preprocessing/discretization.py:187 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/c329936bea1f9410.
Report an issue: GitHub.