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, , shape (N, H, W). This shows where in the image the model found evidence for the class.