{"record":{"id":"3900311fadb39307","repo":"keras-team/keras","slug":"sequential-model-self-name-has-no-defined-inpu","errorCode":null,"errorMessage":"Sequential model '{self.name}' has no defined input shape yet.","messagePattern":"Sequential model '(.+?)' has no defined input shape yet\\.","errorType":"exception","errorClass":"AttributeError","httpStatus":null,"severity":"error","filePath":"keras/src/models/sequential.py","lineNumber":302,"sourceCode":"                **kwargs,\n            )  # Ignore mask\n            inputs = outputs\n        return outputs\n\n    def compute_output_shape(self, input_shape):\n        if self._functional:\n            return self._functional.compute_output_shape(input_shape)\n        # Direct application\n        for layer in self.layers:\n            output_shape = layer.compute_output_shape(input_shape)\n            input_shape = output_shape\n        return output_shape\n\n    @property\n    def input_shape(self):\n        if self._functional:\n            return self._functional.input_shape\n        raise AttributeError(\n            f\"Sequential model '{self.name}' has no defined input shape yet.\"\n        )\n\n    @property\n    def output_shape(self):\n        if self._functional:\n            return self._functional.output_shape\n        raise AttributeError(\n            f\"Sequential model '{self.name}' has no defined output shape yet.\"\n        )\n\n    @property\n    def inputs(self):\n        if self._functional:\n            return self._functional.inputs\n        raise AttributeError(\n            f\"Sequential model '{self.name}' has no defined inputs yet.\"\n        )","sourceCodeStart":284,"sourceCodeEnd":320,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/models/sequential.py#L284-L320","documentation":"The input_shape property only exists once the Sequential has a functional graph, i.e. after build() or after an InputLayer was supplied. Before that there is no input shape to report, so an AttributeError is raised.","triggerScenarios":"model = keras.Sequential([Dense(10)]); print(model.input_shape) before build or calling on data","commonSituations":"Introspection utilities, TensorBoard callbacks, or shape-logging code run before any data passes through the model","solutions":["Call model.build(input_shape) first","Construct with keras.Sequential([keras.Input(...), ...])","Pass input_shape= to the Sequential constructor"],"exampleFix":"# before\nshape = model.input_shape\n\n# after\nmodel.build((None, 28, 28))\nshape = model.input_shape","handlingStrategy":"try-catch","validationCode":"has_input = bool(model._functional) or (\n    model._layers and isinstance(model._layers[0], keras.layers.InputLayer))","typeGuard":null,"tryCatchPattern":"try:\n    shape = model.input_shape\nexcept AttributeError:\n    model.build(input_shape)\n    shape = model.input_shape","preventionTips":["Pass an Input layer or input_shape when constructing the Sequential","Call model.build(shape) before reading .input_shape"],"tags":["keras","sequential","input-shape","lazy-build"],"backgroundTag":"model-not-built","analyzedSha":"7a34a03db60bf60042242d6a556fc3be119046a5","analyzedAt":"2026-08-25T21:25:25.994Z","schemaVersion":2},"datasetVersion":"2026-08-26T02:17:13.382Z"}