{"record":{"id":"01a07d1684a28c32","repo":"keras-team/keras","slug":"invalid-input-shape-for-input-x-with-name-self","errorCode":null,"errorMessage":"Invalid input shape for input {x} with name '{self._inputs[i].name}' and path '{path}'. Expected shape {ref_shape}, but input has incompatible shape {x.shape}","messagePattern":"Invalid input shape for input (.+?) with name '(.+?)' and path '(.+?)'\\. Expected shape (.+?), but input has incompatible shape (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/models/functional.py","lineNumber":316,"sourceCode":"            if x is None:\n                adjusted.append(x)\n                continue\n            x_rank = len(x.shape)\n            ref_rank = len(ref_shape)\n            if x_rank == ref_rank:\n                adjusted.append(x)\n                continue\n            if x_rank == ref_rank + 1:\n                if x.shape[-1] == 1:\n                    adjusted.append(ops.squeeze(x, axis=-1))\n                    continue\n            if x_rank == ref_rank - 1:\n                if ref_shape[-1] == 1:\n                    adjusted.append(ops.expand_dims(x, axis=-1))\n                    continue\n            flat_paths_and_inputs = tree.flatten_with_path(self._inputs_struct)\n            path = \".\".join(str(p) for p in flat_paths_and_inputs[i][0])\n            raise ValueError(\n                f\"Invalid input shape for input {x} with name \"\n                f\"'{self._inputs[i].name}' and path '{path}'. Expected shape \"\n                f\"{ref_shape}, but input has incompatible shape {x.shape}\"\n            )\n        # Add back metadata.\n        for i in range(len(flat_inputs)):\n            if hasattr(flat_inputs[i], \"_keras_history\"):\n                adjusted[i]._keras_history = flat_inputs[i]._keras_history\n            mask = backend.get_keras_mask(flat_inputs[i])\n            if mask is not None:\n                backend.set_keras_mask(adjusted[i], mask)\n        return adjusted\n\n    def _standardize_inputs(self, inputs):\n        raise_exception = False\n        if (\n            isinstance(self._inputs_struct, list)\n            and len(self._inputs_struct) == 1","sourceCodeStart":298,"sourceCodeEnd":334,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/models/functional.py#L298-L334","documentation":"Error \"Invalid input shape for input {x} with name '{self._inputs[i].name}' and path '{path}'. Expected shape {ref_shape}, but input has incompatible shape {x.shape}\" thrown in keras-team/keras.","triggerScenarios":"Thrown at keras/src/models/functional.py:316 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"}