keras-team/keras · error · ValueError

Scaling is invalid, it must be `None`, 'density' or…

Error message

Scaling is invalid, it must be `None`, 'density' or 'spectrum'. Received scaling={scaling}

What it means

Constructor guard in STFTSpectrogram.__init__: scaling was set to something other than None, 'density' or 'spectrum'. Scaling only applies when converting STFT results to power spectra, and only these two conventions are implemented.

Solutions

  1. Set scaling to None (no scaling), 'density' (power spectral density), or 'spectrum' (power spectrum)
  2. Check for typos; the strings are matched exactly
Defensive patterns

Strategy: validation

When it happens

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

Appendix: source

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

                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
            scipy.signal.get_window(window, 1)

        super().__init__(**kwargs)

        self.mode = mode

View on GitHub (pinned to 7a34a03db6)