keras-team/keras · error · ValueError

The shape of `window` must be equal to…

Error message

The shape of `window` must be equal to [sequence_length].Received: window shape={win_array.shape}

What it means

Raised by the window-shape guard in keras/src/backend/tensorflow/math.py stft: when window is supplied as an array/tensor rather than a string, its length must exactly equal sequence_length so it multiplies each frame elementwise. The supplied window's shape differs from [sequence_length], so the elementwise multiply would fail.

Solutions

  1. Provide a window tensor of exactly sequence_length samples
  2. Regenerate the window with the current sequence_length (e.g. tf.signal.hann_window(sequence_length))
  3. Slice or pad the window to match sequence_length if appropriate
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at keras/src/backend/tensorflow/math.py:220 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/6f62e47e23972520. Report an issue: GitHub.

Appendix: source

Thrown at keras/src/backend/tensorflow/math.py:220

        x = tf.pad(x, pad_width, mode="reflect")

    l_pad = (fft_length - sequence_length) // 2
    r_pad = fft_length - sequence_length - l_pad

    if window is not None:
        if isinstance(window, str):
            if window == "hann":
                win_array = tf.signal.hann_window(
                    sequence_length, periodic=True, dtype=x.dtype
                )
            else:
                win_array = tf.signal.hamming_window(
                    sequence_length, periodic=True, dtype=x.dtype
                )
        else:
            win_array = convert_to_tensor(window, dtype=x.dtype)
        if len(win_array.shape) != 1 or win_array.shape[-1] != sequence_length:
            raise ValueError(
                "The shape of `window` must be equal to [sequence_length]."
                f"Received: window shape={win_array.shape}"
            )
        win_array = tf.pad(win_array, [[l_pad, r_pad]])

        def win(frame_step, dtype):
            return win_array

    else:
        win = None

    result = tf.signal.stft(
        x,
        frame_length=(sequence_length + l_pad + r_pad),
        frame_step=sequence_stride,
        fft_length=fft_length,
        window_fn=win,
    )

View on GitHub (pinned to 7a34a03db6)