{"record":{"id":"e270075c6bc6cdfc","repo":"keras-team/keras","slug":"sequential-model-self-name-has-no-defined-outp","errorCode":null,"errorMessage":"Sequential model '{self.name}' has no defined output shape yet.","messagePattern":"Sequential model '(.+?)' has no defined output shape yet\\.","errorType":"exception","errorClass":"AttributeError","httpStatus":null,"severity":"error","filePath":"keras/src/models/sequential.py","lineNumber":310,"sourceCode":"        # 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        )\n\n    @property\n    def outputs(self):\n        if self._functional:\n            return self._functional.outputs\n        raise AttributeError(\n            f\"Sequential model '{self.name}' has no defined outputs yet.\"\n        )","sourceCodeStart":292,"sourceCodeEnd":328,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/models/sequential.py#L292-L328","documentation":"output_shape requires the model to be built (functional graph present). An unbuilt Sequential has undefined output shape, hence the AttributeError.","triggerScenarios":"Accessing model.output_shape on a Sequential that has never been built or called","commonSituations":"Asserting output dimensions in tests, wiring heads to matching shapes, plotting model summaries before fitting","solutions":["Build the model (build() or a forward pass on real data)","Add an InputLayer first","Use model.compute_output_shape(input_shape) to probe without building"],"exampleFix":"# before\nout = model.output_shape\n\n# after\nmodel.build((None, 28, 28))\nout = model.output_shape","handlingStrategy":"try-catch","validationCode":"has_output = bool(model._functional) or len(model._layers) > 0","typeGuard":null,"tryCatchPattern":"try:\n    shape = model.output_shape\nexcept AttributeError:\n    model.build(input_shape)\n    shape = model.output_shape","preventionTips":["Build the model or pass an Input layer first","Feed one batch through the model to build it before querying .output_shape"],"tags":["keras","sequential","output-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"}