{"record":{"id":"3be4c9ebbd5c8634","repo":"keras-team/keras","slug":"you-cannot-pass-both-batch-size-and-batch-shape","errorCode":null,"errorMessage":"You cannot pass both `batch_size` and `batch_shape` at the same time.","messagePattern":"You cannot pass both `batch_size` and `batch_shape` at the same time\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/layers/core/input_layer.py","lineNumber":84,"sourceCode":"                    \"When providing the `input_tensor` argument, you \"\n                    \"cannot provide an incompatible `dtype` argument.\"\n                )\n            if sparse is not None and input_tensor.sparse != sparse:\n                raise ValueError(\n                    \"When providing the `input_tensor` argument, you \"\n                    \"cannot provide an incompatible `sparse` argument.\"\n                )\n            batch_shape = input_tensor.shape\n            dtype = input_tensor.dtype\n            sparse = input_tensor.sparse\n        else:\n            if shape is not None and batch_shape is not None:\n                raise ValueError(\n                    \"You cannot pass both `shape` and `batch_shape` at the \"\n                    \"same time.\"\n                )\n            if batch_size is not None and batch_shape is not None:\n                raise ValueError(\n                    \"You cannot pass both `batch_size` and `batch_shape` \"\n                    \"at the same time.\"\n                )\n            if shape is None and batch_shape is None:\n                raise ValueError(\"You must pass a `shape` argument.\")\n\n            if shape is not None:\n                shape = backend.standardize_shape(shape)\n                batch_shape = (batch_size,) + shape\n\n        self._batch_shape = backend.standardize_shape(batch_shape)\n        self._dtype = backend.standardize_dtype(dtype)\n        self.sparse = bool(sparse)\n        if self.sparse and not backend.SUPPORTS_SPARSE_TENSORS:\n            raise ValueError(\n                f\"`sparse=True` is not supported with the {backend.backend()} \"\n                \"backend\"\n            )","sourceCodeStart":66,"sourceCodeEnd":102,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/layers/core/input_layer.py#L66-L102","documentation":"Guard in InputLayer.__init__ (no input_tensor branch): `batch_size` is a convenience prefix that is combined with `shape`, while `batch_shape` already contains the batch dimension. Supplying both would define the batch axis twice, so the combination is rejected.","triggerScenarios":"Thrown at keras/src/layers/core/input_layer.py:84 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Use batch_size together with shape, e.g. Input(shape=(32,), batch_size=64)","Use batch_shape alone with the batch axis included, e.g. Input(batch_shape=(64, 32))"],"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"}