keras-team/keras · error · ValueError
Input should have its last dimension fully-defined. Received
Error message
Input should have its last dimension fully-defined. Received: input.shape = {real.shape} What it means
The 1D FFT needs the FFT length known at symbolic-inference time, so the last dimension of the input must be fully defined (not None). Keras raises when real.shape[-1] is None during functional-model construction or with dynamic shapes.
Source
Thrown at keras/src/ops/math.py:526
if real.shape != imag.shape:
raise ValueError(
"Input `x` should be a tuple of two tensors - real and "
"imaginary. Both the real and imaginary parts should have the "
f"same shape. Received: x[0].shape = {real.shape}, "
f"x[1].shape = {imag.shape}"
)
# We are calculating 1D FFT. Hence, rank >= 1.
if len(real.shape) < 1:
raise ValueError(
f"Input should have rank >= 1. "
f"Received: input.shape = {real.shape}"
)
# The axis along which we are calculating FFT should be fully-defined.
m = real.shape[-1]
if m is None:
raise ValueError(
f"Input should have its last dimension fully-defined. "
f"Received: input.shape = {real.shape}"
)
return (
KerasTensor(shape=real.shape, dtype=real.dtype),
KerasTensor(shape=imag.shape, dtype=imag.dtype),
)
def call(self, x):
return backend.math.fft(x)
@keras_export("keras.ops.fft")
def fft(x):
"""Computes the Fast Fourier Transform along last axis of input.
Args:View on GitHub (pinned to 7a34a03db6)
Solutions
- Give the input a fixed last dimension: keras.Input(shape=(fft_len,))
- Pad/ragged-to-dense to a fixed length before the FFT
- If lengths vary, bucket inputs to a few fixed sizes or compute the FFT eagerly outside the symbolic graph
- Rebuild with concrete tensors so the last dim is known
Example fix
# before inputs = keras.Input(shape=(None,)) # dynamic length out = keras.ops.fft((inputs, inputs)) # after inputs = keras.Input(shape=(256,)) # fixed fft length out = keras.ops.fft((inputs, inputs))
Defensive patterns
Strategy: validation
Validate before calling
assert real.shape[-1] is not None, 'last dim must be static for fft'
Prevention
- Use fixed-length keras.Input for FFT models
- Pad variable sequences to a constant length before the graph
When it happens
Trigger: Using a keras.Input(shape=(None,)) (dynamic sequence length) and calling keras.ops.fft inside a functional model; JAX/TF traces with an undefined last dim.
Common situations: Variable-length audio/text pipelines with dynamic timesteps feeding an FFT layer; migrating from eager execution to a functional/Layer workflow where shapes become symbolic.
Related errors
- Input should have its {axes} axes fully-defined. Received: i
- The `weights` argument should be either `None` (random initi
- RandomCrop requires the input to have a fully defined height
- All `axis` values to be kept must have a known shape. Receiv
- R2Score expects 2D inputs with shape (batch_size, output_dim
AI-assisted analysis of keras-team/keras@7a34a03db6 (2026-08-25).
Data as JSON: /api/errors/62d85d3769c00b2b.
Report an issue: GitHub.