keras-team/keras · error · ValueError

Input length must be statically known for adaptive pooling

Error message

Input length must be statically known for adaptive pooling

What it means

Error "Input length must be statically known for adaptive pooling" thrown in keras-team/keras.

Source

Thrown at keras/src/backend/tensorflow/nn.py:340

    small_indices = window_starts
    big_indices = window_starts + small_pool_len

    gather_indices = tf.where(is_big_window, big_indices, small_indices)
    return tf.cast(gather_indices, tf.int32)


def _adaptive_average_pool1d(inputs, output_size, data_format="channels_first"):
    if isinstance(output_size, int):
        output_size = (output_size,)
    if data_format == "channels_first":
        inputs = tf.transpose(inputs, (0, 2, 1))

    static_shape = inputs.shape.as_list()
    l_static = static_shape[1]
    out_l = output_size[0]

    if l_static is None:
        raise ValueError(
            "Input length must be statically known for adaptive pooling"
        )

    small_l, big_l = compute_adaptive_pooling_window_sizes(l_static, out_l)
    gather_l = _compute_static_gather_indices(l_static, out_l, small_l, big_l)

    small_pool_l = tf.nn.pool(
        inputs,
        window_shape=(small_l,),
        pooling_type="AVG",
        strides=(1,),
        padding="VALID",
        data_format="NWC",
    )
    big_pool_l = tf.nn.pool(
        inputs,
        window_shape=(big_l,),
        pooling_type="AVG",

View on GitHub (pinned to 7a34a03db6)

When it happens

Trigger: Thrown at keras/src/backend/tensorflow/nn.py:340 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/ed7e8fc5a2a8de29. Report an issue: GitHub.