Max Pooling Layer
Max pooling is a downsampling operation commonly used in Convolutional Neural Networks (CNNs). It reduces the spatial dimensions of the input by selecting the **maximum value** within each non-overlapping window (pool) of a given size.
Algorithm:
For each pool_size x pool_size window in the input:
output[i, j] = max(input[i*pool_size : (i+1)*pool_size, j*pool_size : (j+1)*pool_size])
Output dimensions:
output_height = input_height / pool_size
output_width = input_width / pool_size
Example:
Input: [[1, 2, 3, 4], pool_size = 2
[5, 6, 7, 8],
[9, 10, 11, 12],
[13, 14, 15, 16]]
Window 1: [[1,2],[5,6]] -> max = 6
Window 2: [[3,4],[7,8]] -> max = 8
Window 3: [[9,10],[13,14]] -> max = 14
Window 4: [[11,12],[15,16]] -> max = 16
Output: [[6, 8],
[14, 16]]
Max pooling helps reduce computational cost, provides a form of translation invariance, and helps prevent overfitting by progressively reducing the spatial size of the representation. It retains the most prominent features (highest activations) from each local region.
Constraints:
Test Cases
[[1,2],[3,4]] 2[[4]][[1,2,3],[4,5,6],[7,8,9]] 2[[6,9]]