#134Global average poolingEasyCNNComputer Vision
Global average pooling
Background
Modern CNN classifier heads often replace "flatten + big dense layer" with global average pooling: collapse each feature map to a single number by averaging over all its spatial positions. A (H, W, C) feature volume becomes a length-C vector — one summary per channel.
Problem statement
Implement global_avg_pool(volume) returning the per-channel spatial mean.
Input
volume— array-like of shape(H, W, C).
Output
Returns an np.ndarray of shape (C,).
Examples
Example 1 — single channel
Input: volume = [[[1], [3]], [[2], [6]]]
Output: [3.]
Explanation: mean of is .
Example 2 — two channels
Input: volume = [[[1, 10], [3, 30]], [[2, 20], [6, 60]]]
Output: [ 3. 30.]
Constraints
- Average over the spatial axes (0 and 1), keeping the channel axis.
- Return shape
(C,).
Notes
- Global average pooling has no parameters and is translation-tolerant — a big reason it replaced giant flatten+dense heads in architectures like ResNet.
Python
Loading...
▶ Run executes the 3 visible sample tests below in your browser. Submit runs the full suite — including hidden tests — on the server for an official verdict.
- •example single channel
- •reference two channels
- •sample uniform 2x2x1