Class Activation Map (Zhou 2016) — visualization helpers.
The heavy lifts (CAM compute, bilinear upsample, logit recomputation)
are in F32Array.lean via FFI. This file provides:
viridis : Float → (UInt8 × UInt8 × UInt8)— perceptually uniform 256-entry colormap (also legible in greyscale).overlayHeatmap : ...— α-blend a heatmap over an RGB image.writePPM : ...— binary P6 PPM serializer (zero deps; convert to PNG viaconvertoutside if final asset size matters).
No autodiff is needed — for any network ending in
... → globalAvgPool → dense ic oc act GradCAM collapses to the
closed form Zhou et al. computed three years before Selvaraju et al.
generalized it. See planning/archive/gradcam.md.
α-blend a heatmap over an RGB image and emit the result as a
contiguous [H, W, 3] UInt8 buffer (PPM-ready).
imgRGB: already-denormalized[H, W, 3]UInt8 (R, G, B interleaved row-major). Caller is responsible for the ImageNet-mean/std de-normalization for whatever dataset.heat: f32[H, W]with values in[0, 1].
Equations
- One or more equations did not get rendered due to their size.
Instances For
Write a binary P6 PPM file. pixels is [H, W, 3] UInt8 row-major.