🐆

What is Global Max Pooling?

2024/05/28に公開

1. Global Max Pooling

Global Max Pooling (GMP) reduces each feature map to a single value, taking the maximum value of the entire feature map. This drastically reduces the spatial dimensions of the feature maps.

For example, GMP outputs a shape (1, 3) when input that has size (1, 10, 10 ,3)(batchsize, height, width, channel) is provided. It shows GMP extarct a value from whole each input.

・GMP

import tensorflow as tf
from tensorflow.keras.layers import GlobalMaxPooling2D

# Sample input tensor of shape (batch_size, height, width, channels)
input_tensor = tf.random.normal([1, 10, 10, 3])

# Global Max Pooling
gmp_layer = GlobalMaxPooling2D()
output_tensor = gmp_layer(input_tensor)

print("Input Shape: ", input_tensor.shape)
print("Output Shape: ", output_tensor.shape)

### output
# Input Shape:  (1, 10, 10, 3)
# Output Shape:  (1, 3) # like [x, x, x]

GMP extarcted max value of each channel and compress dimention of the array.

・Normal Pooling (2x2 window)
In contrast, normal pooling doesn't change the number of dimentional.

import tensorflow as tf
from tensorflow.keras.layers import MaxPooling2D

# Sample input tensor of shape (batch_size, height, width, channels)
input_tensor = tf.random.normal([1, 10, 10, 3])

# Max Pooling with a 2x2 window
mp_layer = MaxPooling2D(pool_size=(2, 2))
output_tensor = mp_layer(input_tensor)

print("Input Shape: ", input_tensor.shape)
print("Output Shape: ", output_tensor.shape)

### output
# Input Shape:  (1, 10, 10, 3)
# Output Shape:  (1, 5, 5, 3) 

Summary

GMP extracts max value from whole each input. It is the reason that it called "Global" pooling.

Discussion