{"record":{"id":"4f5f48a837a79ee8","repo":"keras-team/keras","slug":"we-could-not-automatically-infer-the-shape-of-the","errorCode":null,"errorMessage":"We could not automatically infer the shape of the Lambda's output. Please specify the `output_shape` argument for this Lambda layer.","messagePattern":"We could not automatically infer the shape of the Lambda's output\\. Please specify the `output_shape` argument for this Lambda layer\\.","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"keras/src/layers/core/lambda_layer.py","lineNumber":95,"sourceCode":"        # Warning on every invocation will be quite irksome in Eager mode.\n        self._already_warned = False\n\n        function_args = inspect.getfullargspec(function).args\n        self._fn_expects_training_arg = \"training\" in function_args\n        self._fn_expects_mask_arg = \"mask\" in function_args\n\n    def compute_output_shape(self, input_shape):\n        if self._output_shape is None:\n            # Leverage backend shape inference\n            try:\n                inputs = tree.map_shape_structure(\n                    lambda x: backend.KerasTensor(x, dtype=self.compute_dtype),\n                    input_shape,\n                )\n                output_spec = backend.compute_output_spec(self.call, inputs)\n                return tree.map_structure(lambda x: x.shape, output_spec)\n            except:\n                raise NotImplementedError(\n                    \"We could not automatically infer the shape of \"\n                    \"the Lambda's output. Please specify the `output_shape` \"\n                    \"argument for this Lambda layer.\"\n                )\n\n        if callable(self._output_shape):\n            return self._output_shape(input_shape)\n\n        # Output shapes are passed directly and don't include batch dimension.\n        batch_size = tree.flatten(input_shape)[0]\n\n        def _add_batch(shape):\n            return (batch_size,) + shape\n\n        return tree.map_shape_structure(_add_batch, self._output_shape)\n\n    def call(self, inputs, mask=None, training=None):\n        # We must copy for thread safety,","sourceCodeStart":77,"sourceCodeEnd":113,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/layers/core/lambda_layer.py#L77-L113","documentation":"Error \"We could not automatically infer the shape of the Lambda's output. Please specify the `output_shape` argument for this Lambda layer.\" thrown in keras-team/keras.","triggerScenarios":"Thrown at keras/src/layers/core/lambda_layer.py:95 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"}