keras-team/keras · error · ValueError
Input should have rank >= 1. Received: input.shape = {real.s
Error message
Input should have rank >= 1. Received: input.shape = {real.shape} What it means
keras.ops.fft computes a 1D FFT over the last axis, so every input (real and imaginary part) must have at least one dimension. A rank-0 scalar tensor fails this check in compute_output_spec.
Source
Thrown at keras/src/ops/math.py:518
if not isinstance(x, (tuple, list)) or len(x) != 2:
raise ValueError(
"Input `x` should be a tuple of two tensors - real and "
f"imaginary. Received: x={x}"
)
real, imag = x
# Both real and imaginary parts should have the same shape.
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):View on GitHub (pinned to 7a34a03db6)
Solutions
- Keep at least a length-1 vector: reshape scalars to shape (1,) or (n,) before the call
- Audit reductions upstream (mean/sum/max) and add keepdims=True
- Use keras.ops.expand_dims(x, -1) if the signal may be scalar
Example fix
# before sig = keras.ops.mean(x) # scalar out = keras.ops.fft((sig, keras.ops.zeros_like(sig))) # after sig = keras.ops.mean(x, keepdims=True) # shape (1,) out = keras.ops.fft((sig, keras.ops.zeros_like(sig)))
Defensive patterns
Strategy: validation
Validate before calling
assert len(real.shape) >= 1 and len(imag.shape) >= 1
Prevention
- Use keepdims=True on reductions feeding FFTs
- Expand dims defensively for possibly-scalar signals
When it happens
Trigger: Passing scalar tensors like keras.ops.cast(3.0, 'float32') as either part; aggressive reduction (sum/mean without keepdims) collapsing the signal to a scalar before the FFT.
Common situations: Preprocessing that aggregates the time series (mean/variance normalization) forgetting keepdims=True, or unit tests using trivial scalar placeholders.
Related errors
- Input `x` should be a tuple of two tensors - real and imagin
- Input should have rank >= 2. Received: input.shape = {real.s
- Layer {self.name} weight shape {variable.shape} is not compa
- Expected rebatched data to have batch size 1. Received: shap
- Expected as input a list/tuple of 2 tensors. Received input_
AI-assisted analysis of keras-team/keras@7a34a03db6 (2026-08-25).
Data as JSON: /api/errors/04ebfaeead893c0a.
Report an issue: GitHub.