{"record":{"id":"3334a52a53fd5486","repo":"keras-team/keras","slug":"you-need-to-either-pass-the-bin-boundaries-argum","errorCode":null,"errorMessage":"You need to either pass the `bin_boundaries` argument at construction time or call `adapt(dataset)` before you can start using the `Discretization` layer.","messagePattern":"You need to either pass the `bin_boundaries` argument at construction time or call `adapt\\(dataset\\)` before you can start using the `Discretization` layer\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/layers/preprocessing/discretization.py","lineNumber":281,"sourceCode":"                    (input_shape[0],) + tuple(input_shape[2:]) + (depth,)\n                )\n                return out_shape\n            else:\n                return (depth,)\n\n    def compute_output_spec(self, inputs):\n        output_shape = self.compute_output_shape(inputs.shape)\n        return backend.KerasTensor(shape=output_shape, dtype=self.output_dtype)\n\n    def load_own_variables(self, store):\n        if len(store) == 1:\n            # Legacy format case\n            self.summary = store[\"0\"]\n        return\n\n    def call(self, inputs):\n        if self.bin_boundaries is None:\n            raise ValueError(\n                \"You need to either pass the `bin_boundaries` argument at \"\n                \"construction time or call `adapt(dataset)` before you can \"\n                \"start using the `Discretization` layer.\"\n            )\n\n        indices = self.backend.numpy.digitize(inputs, self.bin_boundaries)\n        return numerical_utils.encode_categorical_inputs(\n            indices,\n            output_mode=self.output_mode,\n            depth=len(self.bin_boundaries) + 1,\n            dtype=self.output_dtype,\n            sparse=self.sparse,\n            backend_module=self.backend,\n        )\n\n    def get_config(self):\n        return {\n            \"bin_boundaries\": self.bin_boundaries,","sourceCodeStart":263,"sourceCodeEnd":299,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/layers/preprocessing/discretization.py#L263-L299","documentation":"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.","triggerScenarios":"Thrown at keras/src/layers/preprocessing/discretization.py:281 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","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)"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"7a34a03db60bf60042242d6a556fc3be119046a5","analyzedAt":"2026-08-25T21:25:25.994Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}