{"record":{"id":"c329936bea1f9410","repo":"keras-team/keras","slug":"cannot-adapt-a-discretization-layer-that-has-been","errorCode":null,"errorMessage":"Cannot adapt a Discretization layer that has been initialized with `bin_boundaries`, use `num_bins` instead.","messagePattern":"Cannot adapt a Discretization layer that has been initialized with `bin_boundaries`, use `num_bins` instead\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/layers/preprocessing/discretization.py","lineNumber":187,"sourceCode":"        input dataset. The number of quantiles can be controlled via the\n        `num_bins` argument, and the error tolerance for quantile boundaries can\n        be controlled via the `epsilon` argument.\n\n        Arguments:\n            data: The data to train on. It can be passed either as a\n                batched `tf.data.Dataset`, a Grain dataset, as a NumPy\n                array, or as any iterable of batches (e.g. a list of\n                arrays or a generator yielding batches).\n            steps: Integer or `None`.\n                Total number of steps (batches of samples) to process.\n                If `data` is a `tf.data.Dataset`, and `steps` is `None`,\n                `adapt()` will run until the input dataset is exhausted.\n                When passing an infinitely\n                repeating dataset, you must specify the `steps` argument. This\n                argument is not supported with array inputs or list inputs.\n        \"\"\"\n        if self.num_bins is None:\n            raise ValueError(\n                \"Cannot adapt a Discretization layer that has been initialized \"\n                \"with `bin_boundaries`, use `num_bins` instead.\"\n            )\n        self.reset_state()\n        if isinstance(data, tf.data.Dataset):\n            if steps is None and hasattr(data, \"cardinality\"):\n                cardinality = data.cardinality()\n                if cardinality.numpy() not in (\n                    tf.data.UNKNOWN_CARDINALITY,\n                    tf.data.INFINITE_CARDINALITY,\n                ):\n                    steps = int(cardinality.numpy())\n\n            progbar = Progbar(target=steps, unit_name=\"step\")\n            if steps is not None:\n                data = data.take(steps)\n            for i, batch in enumerate(data):\n                self.update_state(batch)","sourceCodeStart":169,"sourceCodeEnd":205,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/layers/preprocessing/discretization.py#L169-L205","documentation":"Error \"Cannot adapt a Discretization layer that has been initialized with `bin_boundaries`, use `num_bins` instead.\" thrown in keras-team/keras.","triggerScenarios":"Thrown at keras/src/layers/preprocessing/discretization.py:187 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"7a34a03db60bf60042242d6a556fc3be119046a5","analyzedAt":"2026-08-25T21:25:25.994Z","schemaVersion":2},"datasetVersion":"2026-08-26T02:17:13.382Z"}