conventions.io

Tech Challenge

2026-09-01

🤖

Daily Tech Challenge

AI & ML

medium
Question 1 of 5

Grad-CAM produces a class-discriminative heatmap for a trained CNN. Given the hook-based implementation below, what does it actually compute?

Example
# A: activations of the LAST conv layer, shape (1, C, H, W)
# G: gradient of the class-c score w.r.t. A, same shape
score = model(x)[0, c]
score.backward()                                  # populates G

alpha = G.mean(dim=(2, 3), keepdim=True)          # (1, C, 1, 1)
cam   = torch.relu((alpha * A).sum(dim=1))        # (1, H, W)  e.g. 7x7
cam   = F.interpolate(cam[None], size=x.shape[-2:], mode='bilinear')

Tuesday, September 1, 2026 · A new challenge drops every day