keras-team/keras · error · ValueError

Output mode is invalid, it must be one of

Error message

Output mode is invalid, it must be one of {', '.join(all_modes)}. Received: mode={mode}

What it means

Constructor guard in STFTSpectrogram.__init__: the mode argument is not one of the layer's enumerated output modes ('log', 'magnitude', 'psd', 'real', 'imag', 'angle', 'stft'). The offending value is the mode string, echoed in the message.

Solutions

  1. Use one of: 'log', 'magnitude', 'psd', 'real', 'imag', 'angle', 'stft'
  2. Check for typos/case in the mode string; values are matched exactly
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at keras/src/layers/preprocessing/stft_spectrogram.py:172 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/4a1dd9d7d4633aff. Report an issue: GitHub.

Appendix: source

Thrown at keras/src/layers/preprocessing/stft_spectrogram.py:172

                f"frame_length={frame_length}"
            )

        if fft_length is not None and fft_length < frame_length:
            raise ValueError(
                "`fft_length` should be not less than `frame_length`. "
                f"Received fft_length={fft_length}, frame_length={frame_length}"
            )

        if fft_length is not None and (fft_length & -fft_length) != fft_length:
            warnings.warn(
                "`fft_length` is recommended to be a power of two. "
                f"Received fft_length={fft_length}"
            )

        all_modes = ["log", "magnitude", "psd", "real", "imag", "angle", "stft"]

        if mode not in all_modes:
            raise ValueError(
                "Output mode is invalid, it must be one of "
                f"{', '.join(all_modes)}. Received: mode={mode}"
            )

        if scaling is not None and scaling not in ["density", "spectrum"]:
            raise ValueError(
                "Scaling is invalid, it must be `None`, 'density' "
                f"or 'spectrum'. Received scaling={scaling}"
            )

        if padding not in ["valid", "same"]:
            raise ValueError(
                "Padding is invalid, it should be 'valid', 'same'. "
                f"Received: padding={padding}"
            )

        if isinstance(window, str):
            # throws an exception for invalid window function

View on GitHub (pinned to 7a34a03db6)