Implement Global Average Pooling (GAP) over spatial dimensions for channel-first tensors.
• If input x has shape (C, H, W) → output is shape (C,)
• If input x has shape (N, C, H, W) → output is shape (N, C)
Input: x = np.ones((3, 2, 2))
Output: [1., 1., 1.]
Each channel has all 1s, so average = 1
Input: x = np.array([[[[1,2],[3,4]]]]) (shape (1,1,2,2))
Output: [[2.5]]
(1+2+3+4)/4 = 2.5
Sign in to take notes on this problem
Accepts: array
Implement Global Average Pooling (GAP) over spatial dimensions for channel-first tensors.
• If input x has shape (C, H, W) → output is shape (C,)
• If input x has shape (N, C, H, W) → output is shape (N, C)
Input: x = np.ones((3, 2, 2))
Output: [1., 1., 1.]
Each channel has all 1s, so average = 1
Input: x = np.array([[[[1,2],[3,4]]]]) (shape (1,1,2,2))
Output: [[2.5]]
(1+2+3+4)/4 = 2.5
Sign in to take notes on this problem
Accepts: array