keras-team/keras · error · ValueError

Input spatial dimensions must be statically known for adapti

Error message

Input spatial dimensions must be statically known for adaptive pooling

What it means

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

Source

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

    if data_format == "channels_first":
        pooled_l = tf.transpose(pooled_l, (0, 2, 1))
    return pooled_l


def _adaptive_average_pool2d(inputs, output_size, data_format="channels_first"):
    if isinstance(output_size, int):
        output_size = (output_size, output_size)

    if data_format == "channels_first":
        inputs = tf.transpose(inputs, (0, 2, 3, 1))

    static_shape = inputs.shape.as_list()
    h_static = static_shape[1]
    w_static = static_shape[2]
    out_h, out_w = output_size

    if h_static is None or w_static is None:
        raise ValueError(
            "Input spatial dimensions must be "
            "statically known for adaptive pooling"
        )

    small_h, big_h = compute_adaptive_pooling_window_sizes(h_static, out_h)
    small_w, big_w = compute_adaptive_pooling_window_sizes(w_static, out_w)

    gather_h = _compute_static_gather_indices(h_static, out_h, small_h, big_h)
    gather_w = _compute_static_gather_indices(w_static, out_w, small_w, big_w)

    small_pool_h = tf.nn.pool(
        inputs,
        window_shape=(small_h, 1),
        pooling_type="AVG",
        strides=(1, 1),
        padding="VALID",
        data_format="NHWC",
    )

View on GitHub (pinned to 7a34a03db6)

When it happens

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