<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/keras-team/keras/tree/v3.15.1/keras/src/ops/nn.py#L1212-L1263) |

Adaptive max pooling operation.

#### View aliases


**Main aliases**

[`tf.keras.ops.nn.adaptive_max_pool`](https://www.tensorflow.org/api_docs/python/tf/keras/ops/adaptive_max_pool)

<br />

    tf.keras.ops.adaptive_max_pool(
        inputs, output_size, data_format=None
    )

Applies an adaptive max pooling operation that automatically computes the
kernel size and stride to pool the input to the specified `output_size`.
This operation is useful when you want a fixed output size regardless of
input size, commonly used in models like ResNet for global feature
extraction.
Args:
inputs: Tensor of rank 4. Input tensor of shape:

        - If `data_format="channels_last"`:
            `(batch_size, height, width, channels)`.
        - If `data_format="channels_first"`:
            `(batch_size, channels, height, width)`.
    output_size: Integer or tuple/list of 2 integers, specifying the target
        output spatial dimensions `(output_height, output_width)`. If a
        single
        integer is provided, the same value is used for both dimensions.
    data_format: string, either `"channels_last"` or `"channels_first"`.
        Defaults to the value found in your Keras config file at
        `~/.keras/keras.json`. If never set, defaults to `"channels_last"`.

<br />

<br />

<br />

| ## Returns ||
|---|---|
| A tensor of rank 4 representing the adaptive max pooled result. ||

<br />

#### Example:

    x = np.random.rand(2, 64, 64, 3)
    y = keras.ops.adaptive_max_pool(x, output_size=(32, 32))
    y.shape
    (2, 32, 32, 3)

    # Works with any input size
    x = np.random.rand(2, 100, 80, 3)
    y = keras.ops.adaptive_max_pool(x, output_size=7)
    y.shape
    (2, 7, 7, 3)