keras-team/keras · error · NotImplementedError
We could not automatically infer the shape of the Lambda's o
Error message
We could not automatically infer the shape of the Lambda's output. Please specify the `output_shape` argument for this Lambda layer.
What it means
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.
Source
Thrown at keras/src/layers/core/lambda_layer.py:95
# Warning on every invocation will be quite irksome in Eager mode.
self._already_warned = False
function_args = inspect.getfullargspec(function).args
self._fn_expects_training_arg = "training" in function_args
self._fn_expects_mask_arg = "mask" in function_args
def compute_output_shape(self, input_shape):
if self._output_shape is None:
# Leverage backend shape inference
try:
inputs = tree.map_shape_structure(
lambda x: backend.KerasTensor(x, dtype=self.compute_dtype),
input_shape,
)
output_spec = backend.compute_output_spec(self.call, inputs)
return tree.map_structure(lambda x: x.shape, output_spec)
except:
raise NotImplementedError(
"We could not automatically infer the shape of "
"the Lambda's output. Please specify the `output_shape` "
"argument for this Lambda layer."
)
if callable(self._output_shape):
return self._output_shape(input_shape)
# Output shapes are passed directly and don't include batch dimension.
batch_size = tree.flatten(input_shape)[0]
def _add_batch(shape):
return (batch_size,) + shape
return tree.map_shape_structure(_add_batch, self._output_shape)
def call(self, inputs, mask=None, training=None):
# We must copy for thread safety,View on GitHub (pinned to 7a34a03db6)
When it happens
Trigger: Thrown at keras/src/layers/core/lambda_layer.py:95 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of keras-team/keras@7a34a03db6 (2026-08-25).
Data as JSON: /api/errors/4f5f48a837a79ee8.
Report an issue: GitHub.