keras-team/keras · error · TypeError

`output_size` must be an integer or (height, width) tuple…

Error message

`output_size` must be an integer or (height, width) tuple. Received: {output_size} of type {type(output_size)}

What it means

AdaptiveAveragePooling2D's output_size is neither an int nor a 2-element (height, width) tuple — it may be None, a float, a 1-tuple, or a 3-tuple. The constructor tries to normalize output_size into an (h, w) pair and raises this when the type/arity does not fit 2D pooling.

Solutions

  1. Pass an int (used for both dims, e.g. 32) or a pair like (224, 224)
  2. Use the 1D or 3D layer variant if your output size tuple has 1 or 3 entries
Defensive patterns

Strategy: type-guard

When it happens

Trigger: Thrown at keras/src/layers/pooling/adaptive_average_pooling2d.py:57 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/94f7061db68d8cd6. Report an issue: GitHub.

Appendix: source

Thrown at keras/src/layers/pooling/adaptive_average_pooling2d.py:57

        - If `data_format="channels_first"`:
            `(batch_size, channels, output_height, output_width)`

    Examples:
        >>> import numpy as np
        >>> input_img = np.random.rand(1, 64, 64, 3)
        >>> layer = AdaptiveAveragePooling2D(output_size=32)
        >>> output_img = layer(input_img)
        >>> output_img.shape
        (1, 32, 32, 3)
    """

    def __init__(self, output_size, data_format=None, **kwargs):
        if isinstance(output_size, int):
            output_size_tuple = (output_size, output_size)
        elif isinstance(output_size, (tuple, list)) and len(output_size) == 2:
            output_size_tuple = tuple(output_size)
        else:
            raise TypeError(
                f"`output_size` must be an integer or (height, width) tuple. "
                f"Received: {output_size} of type {type(output_size)}"
            )

        super().__init__(output_size_tuple, data_format, **kwargs)

View on GitHub (pinned to 7a34a03db6)