keras-team/keras · error · ValueError
You need to either pass the `bin_boundaries` argument at…
Error message
You need to either pass the `bin_boundaries` argument at construction time or call `adapt(dataset)` before you can start using the `Discretization` layer.
What it means
Discretization.call ran while the layer has no boundaries: bin_boundaries is None and adapt() was never called. The layer cannot map inputs to bins without either fixed boundaries or learned quantiles, so it refuses to produce output rather than returning garbage.
Solutions
- Pass bin_boundaries at construction time
- Call layer.adapt(dataset) before using the layer in a model
- Ensure the trained model containing the adapted layer is loaded correctly (check load_own_variables/summary state)
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at keras/src/layers/preprocessing/discretization.py:281 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/3334a52a53fd5486.
Report an issue: GitHub.
Appendix: source
Thrown at keras/src/layers/preprocessing/discretization.py:281
(input_shape[0],) + tuple(input_shape[2:]) + (depth,)
)
return out_shape
else:
return (depth,)
def compute_output_spec(self, inputs):
output_shape = self.compute_output_shape(inputs.shape)
return backend.KerasTensor(shape=output_shape, dtype=self.output_dtype)
def load_own_variables(self, store):
if len(store) == 1:
# Legacy format case
self.summary = store["0"]
return
def call(self, inputs):
if self.bin_boundaries is None:
raise ValueError(
"You need to either pass the `bin_boundaries` argument at "
"construction time or call `adapt(dataset)` before you can "
"start using the `Discretization` layer."
)
indices = self.backend.numpy.digitize(inputs, self.bin_boundaries)
return numerical_utils.encode_categorical_inputs(
indices,
output_mode=self.output_mode,
depth=len(self.bin_boundaries) + 1,
dtype=self.output_dtype,
sparse=self.sparse,
backend_module=self.backend,
)
def get_config(self):
return {
"bin_boundaries": self.bin_boundaries,View on GitHub (pinned to 7a34a03db6)