Global Average Pooling Classification Head

easy
Unit 4 · Optimization & CNNs0/3 to milestone

Modern CNNs and Vision Transformers end with a tiny head: global average pooling collapses each feature map to one number, then a linear layer produces class scores.

Implement:

  • global_avg_pool(x): input (N, C, H, W) → (N, C), the mean over the spatial positions.
  • classify(x, W, b): pool, then pooled @ W + b, where W has shape (C, n_classes). Return the logits.
  • class_activation_map(x, W, class_idx): for each image, the weighted sum of its feature maps using that class's weights, ∑cWc,k⋅xn,c,:,:\sum_c W_{c,k} \cdot x_{n,c,:,:}, shape (N, H, W). This shows where in the image the model found evidence for the class.
#cnn#vision#numpy2 visible + 1 hidden tests
solution.py · Python 3.13
Loading editor…
Run your code to see results. ⌘↵ to run · ⌘⇧↵ to submit
Global Average Pooling Classification Head · TechGradify