Implement global average pooling for channel-first feature maps by averaging every spatial location independently for each channel:
GAP(x)c=HW1h=1∑Hw=1∑Wxc,h,wFor an input with shape (C,H,W), return shape (C,). For a batched input with shape (N,C,H,W), return shape (N,C). The output must be a floating-point NumPy array.
Input: x = [[[1, 1], [1, 1]], [[1, 1], [1, 1]], [[1, 1], [1, 1]]]
Output: [1.0, 1.0, 1.0]
Explanation: Each channel contains four ones, so every channel mean is 1.
Input: x = [[[[1, 2], [3, 4]]]]
Output: [[2.5]]
The spatial dimensions are always the final two axes.
np.mean(x, axis=(-2, -1)) preserves batch and channel axes.
Sign in to take notes on this problem
Accepts: array
Implement global average pooling for channel-first feature maps by averaging every spatial location independently for each channel:
GAP(x)c=HW1h=1∑Hw=1∑Wxc,h,wFor an input with shape (C,H,W), return shape (C,). For a batched input with shape (N,C,H,W), return shape (N,C). The output must be a floating-point NumPy array.
Input: x = [[[1, 1], [1, 1]], [[1, 1], [1, 1]], [[1, 1], [1, 1]]]
Output: [1.0, 1.0, 1.0]
Explanation: Each channel contains four ones, so every channel mean is 1.
Input: x = [[[[1, 2], [3, 4]]]]
Output: [[2.5]]
The spatial dimensions are always the final two axes.
np.mean(x, axis=(-2, -1)) preserves batch and channel axes.
Sign in to take notes on this problem
Accepts: array