Documentation

LeanMlir.Cam

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:

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.

21 evenly spaced stops of matplotlib's viridis (perceptually uniform), linearly interpolated by viridis. Hardcoded so we don't carry a runtime dependency on a colormap file.

Equations
  • One or more equations did not get rendered due to their size.
Instances For

    Map t ∈ [0, 1] to an RGB triple using a lerped viridis palette. Out-of-range t is clamped to [0, 1].

    Equations
    • One or more equations did not get rendered due to their size.
    Instances For
      def Cam.overlayHeatmap (imgRGB heat : ByteArray) (H W : Nat) (alpha : Float) :

      α-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
        def Cam.writePPM (path : String) (H W : Nat) (pixels : ByteArray) :

        Write a binary P6 PPM file. pixels is [H, W, 3] UInt8 row-major.

        Equations
        Instances For