keras-team/keras · error · TypeError
Invalid input type. Expected `float32` or `float64`…
Error message
Invalid input type. Expected `float32` or `float64`. Received: input type={x.dtype} What it means
Raised by the dtype guard at the top of keras/src/backend/tensorflow/math.py stft: tf.signal.stft only accepts float32 or float64 input. The input tensor has some other dtype (e.g. float16, int, or bfloat16), so a TypeError is raised before framing/windowing begins.
Solutions
- Cast x to float32 or float64 before calling stft: x = tf.cast(x, 'float32')
- Avoid passing bfloat16/fp16 activations directly; convert them first
- Check dtype policies (mixed precision) that may cause fp16 inputs
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at keras/src/backend/tensorflow/math.py:181 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/1babb3e83077100b.
Report an issue: GitHub.
Appendix: source
Thrown at keras/src/backend/tensorflow/math.py:181
def rfft(x, fft_length=None):
if fft_length is not None:
fft_length = [fft_length]
complex_output = tf.signal.rfft(x, fft_length=fft_length)
return tf.math.real(complex_output), tf.math.imag(complex_output)
def irfft(x, fft_length=None):
complex_input = _get_complex_tensor_from_tuple(x)
if fft_length is not None:
fft_length = [fft_length]
return tf.signal.irfft(complex_input, fft_length)
def stft(
x, sequence_length, sequence_stride, fft_length, window="hann", center=True
):
if standardize_dtype(x.dtype) not in {"float32", "float64"}:
raise TypeError(
"Invalid input type. Expected `float32` or `float64`. "
f"Received: input type={x.dtype}"
)
if fft_length < sequence_length:
raise ValueError(
"`fft_length` must equal or larger than `sequence_length`. "
f"Received: sequence_length={sequence_length}, "
f"fft_length={fft_length}"
)
if isinstance(window, str):
if window not in {"hann", "hamming"}:
raise ValueError(
"If a string is passed to `window`, it must be one of "
f'`"hann"`, `"hamming"`. Received: window={window}'
)
x = convert_to_tensor(x)
if center:View on GitHub (pinned to 7a34a03db6)