tf.keras.ops.adaptive_average_pool
Stay organized with collections
Save and categorize content based on your preferences.
Adaptive average pooling operation.
tf.keras.ops.adaptive_average_pool(
inputs, output_size, data_format=None
)
Applies an adaptive average 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".
|
Returns |
|
A tensor of rank 4 representing the adaptive average pooled result.
|
Example:
x = np.random.rand(2, 64, 64, 3)
y = keras.ops.adaptive_average_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_average_pool(x, output_size=7)
y.shape
(2, 7, 7, 3)
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates. Some content is licensed under the numpy license.
Last updated 2026-10-31 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2026-10-31 UTC."],[],[]]