{"record":{"id":"ddd2316e244ac5c2","repo":"keras-team/keras","slug":"when-providing-the-input-tensor-argument-you-ca","errorCode":null,"errorMessage":"When providing the `input_tensor` argument, you cannot provide an incompatible `batch_size` argument.","messagePattern":"When providing the `input_tensor` argument, you cannot provide an incompatible `batch_size` argument\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/layers/core/input_layer.py","lineNumber":46,"sourceCode":"                \"Argument `input_shape` is deprecated. Use `shape` instead.\"\n            )\n            shape = kwargs.pop(\"input_shape\")\n        if \"batch_input_shape\" in kwargs:\n            batch_shape = kwargs.pop(\"batch_input_shape\")\n\n        if input_tensor is not None:\n            if not isinstance(input_tensor, backend.KerasTensor):\n                raise ValueError(\n                    \"Argument `input_tensor` must be a KerasTensor. \"\n                    f\"Received invalid type: input_tensor={input_tensor} \"\n                    f\"(of type {type(input_tensor)})\"\n                )\n            if batch_size is not None:\n                if (\n                    len(input_tensor.shape) < 1\n                    or input_tensor.shape[0] != batch_size\n                ):\n                    raise ValueError(\n                        \"When providing the `input_tensor` argument, you \"\n                        \"cannot provide an incompatible `batch_size` argument.\"\n                    )\n            if shape is not None:\n                if (\n                    len(shape) != len(input_tensor.shape) - 1\n                    or shape != input_tensor.shape[1:]\n                ):\n                    raise ValueError(\n                        \"When providing the `input_tensor` argument, you \"\n                        \"cannot provide an incompatible `shape` argument.\"\n                    )\n            if batch_shape is not None and batch_shape != input_tensor.shape:\n                raise ValueError(\n                    \"When providing the `input_tensor` argument, you \"\n                    \"cannot provide an incompatible `batch_shape` argument.\"\n                )\n            if dtype is not None and input_tensor.dtype != dtype:","sourceCodeStart":28,"sourceCodeEnd":64,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/layers/core/input_layer.py#L28-L64","documentation":"Consistency check in InputLayer.__init__: when wrapping an existing input_tensor, an explicit batch_size that conflicts with the tensor's first dimension (including a tensor with no leading batch axis) is rejected, since the wrapped tensor already fixes its own batch size.","triggerScenarios":"Thrown at keras/src/layers/core/input_layer.py:46 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Set batch_size=None and let the tensor's own shape be authoritative","Make batch_size match input_tensor.shape[0] exactly"],"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"}