{"record":{"id":"2136ebb2649ea701","repo":"keras-team/keras","slug":"when-providing-the-input-tensor-argument-you-ca-2136eb","errorCode":null,"errorMessage":"When providing the `input_tensor` argument, you cannot provide an incompatible `batch_shape` argument.","messagePattern":"When providing the `input_tensor` argument, you cannot provide an incompatible `batch_shape` argument\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/layers/core/input_layer.py","lineNumber":60,"sourceCode":"                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:\n                raise ValueError(\n                    \"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:","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/layers/core/input_layer.py#L42-L78","documentation":"Consistency check in InputLayer.__init__: with input_tensor provided, a `batch_shape` argument that disagrees with the tensor's full shape (rank or any dimension) is rejected, because the wrapped tensor already fixes its batch-inclusive shape.","triggerScenarios":"Thrown at keras/src/layers/core/input_layer.py:60 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Omit batch_shape when passing input_tensor","Pass batch_shape exactly equal to tuple(input_tensor.shape), using None for wildcard dimensions of matching rank"],"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"}