keras-team/keras · error · TypeError
Invalid input type. Expected `float16`, `float32` or…
Error message
Invalid input type. Expected `float16`, `float32` or `float64`. Received: input type={dtype} What it means
Runtime type guard in STFTSpectrogram.call(): the dtype of the input tensor is not float16/float32/float64 (e.g. an integer or bfloat16 input). The STFT/FFT ops require real floating-point inputs; the offending value is the input tensor's dtype.
Solutions
- Cast inputs before the layer: x = tf.cast(x, 'float32') or ops.cast(x, 'float32')
- Load/preprocess data as float32/float64 instead of int
- Set the layer's dtype or the model input dtype to a supported float type
Defensive patterns
Strategy: type-guard
When it happens
Trigger: Thrown at keras/src/layers/preprocessing/stft_spectrogram.py:297 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/b46c189a60ff42f0.
Report an issue: GitHub.
Appendix: source
Thrown at keras/src/layers/preprocessing/stft_spectrogram.py:297
outputs,
[batch_size, channels, freq_channels, time_seq],
)
else:
_, freq_channels, time_seq = ops.shape(outputs)
outputs = ops.reshape(
outputs,
[batch_size, channels, freq_channels, time_seq],
)
return outputs
def call(self, inputs):
dtype = inputs.dtype
if backend.standardize_dtype(dtype) not in {
"float16",
"float32",
"float64",
}:
raise TypeError(
"Invalid input type. Expected `float16`, `float32` or "
f"`float64`. Received: input type={dtype}"
)
real_signal = None
imag_signal = None
power = None
if self.mode != "imag":
real_signal = self._apply_conv(inputs, self.real_kernel)
if self.mode != "real":
imag_signal = self._apply_conv(inputs, self.imag_kernel)
if self.mode == "real":
return self._adjust_shapes(real_signal)
elif self.mode == "imag":
return self._adjust_shapes(imag_signal)
elif self.mode == "angle":View on GitHub (pinned to 7a34a03db6)