Skip to main content

Attention & GradCAM

Grad-CAM (CNNs)​

GradCAM hooks a target layer, weights its activations by the spatially averaged gradient of the class logit, applies a ReLU, upsamples to the input size and normalises to [0, 1]. Target layers: the 128→256 convolution for SimpleCNN, the last features block for EfficientNet-B0 (model.gradcam_target). plot_gradcam_grid renders image · heat map · overlay with the predicted class and a ✓ / ✗ marker.

Heat maps are not evidence of physics

A heat map shows where the logit is sensitive, not that the model uses a physically meaningful feature. The figures are qualitative; no quantitative faithfulness test (deletion curves, sanity checks) was run.

DINOv2 attention (ViT)​

For the ViT the explanation is the CLS-token attention of the last block, averaged over the 12 heads and reshaped to the 16×16 patch grid (Caron et al. 2021). The qualitative observation of the project: with the frozen backbone, several heads attend to bright background stars; after fine-tuning, the attention covers the galaxy body. This is read from the figures, not quantified.

◎
Grad-CAM — EfficientNet-B0
Grad-CAM — EfficientNet-B0
Overlay of class-specific heat maps.
◎
Grad-CAM — SimpleCNN
Grad-CAM — SimpleCNN
Same procedure on the from-scratch CNN.
◎
DINOv2 attention, before and after fine-tuning
DINOv2 attention, before and after fine-tuning
CLS-token attention maps.
◎
DINOv2 attention by class
DINOv2 attention by class
Zero-shot backbone.
◎
Attention per head
Attention per head
The 12 heads of the last block.

Attention-guided morphometry​

AttentionMorphometry replaces the Otsu mask of CAS/Gini/M20 with a mask from the fine-tuned DINOv2 attention map (threshold at the 60th percentile, holes filled) and recomputes the statistics on it. The aim is to define the galaxy region by structure rather than brightness. It was applied to 2,000 galaxies, 200 per class.

Do the statistics separate classes better?​

A Kruskal–Wallis statistic across the ten classes measures class separation (larger = better):

StatisticOtsu maskAttention mask
C (concentration)202.0444.4
A (asymmetry)100.9229.3
S (smoothness)150.8305.9
Gini177.8311.2
M2061.6373.0
Notebook 10. All p-values print as 0.0000.
Provenance. Model scores in this section are copied from the output cells of the AstroVision notebooks (and, for DINOv2 per-class recall, read from an exported figure). The documentation data pack contains no metrics file for them, so they cannot be re-derived from the pack; the cell of origin is listed for each value in _facts/astrovision/FACTS_INDEX.md §3 and shown when hovering over a number.

The attention-based statistics have larger KW values for all five measures, most strikingly M20 (61.6 → 373.0).

Not a like-for-like comparison

The Otsu sample has 599 galaxies, the attention sample 2,000; a Kruskal–Wallis H grows with sample size, so part of the gap is a sample-size effect. The two C statistics also use different formulas. The result is suggestive of better class separation, not a measured improvement.

Medians by class (attention masks)​

ClassCAGiniM20Components
0 · Disturbed0.740.360.26−1.151
1 · Merging0.720.420.28−1.171
2 · Round Smooth0.760.360.26−1.031
3 · In-between Round Smooth0.770.350.25−1.041
4 · Cigar Shaped Smooth0.780.360.25−0.971
5 · Barred Spiral0.690.320.29−1.361
6 · Unbarred Tight Spiral0.680.330.30−1.401
7 · Unbarred Loose Spiral0.710.350.28−1.231
8 · Edge-on without Bulge0.710.340.28−1.201
9 · Edge-on with Bulge0.750.380.27−0.991
Source: data/attn_morphometry_df.csv. Values are not comparable with the Otsu-mask medians of the Morphometry page.

The median number of connected components is 1 even for Merging galaxies: a 16×16 attention map thresholded at a percentile yields one blob almost always, so the method cannot count multiple nuclei.

Correlations of the attention statistics with SDSS g−r are tiny: ρ = +0.070 for C and +0.087 for M20 (1,957 galaxies). Significant at p < 0.05 with this many galaxies, but explaining under 1 % of the variance.

◎
Attention masks
Attention masks
Galaxy, attention map and mask.
◎
Mask components
Mask components
Connected components of the attention masks.
◎
Attention versus Otsu
Attention versus Otsu
Per-class distributions of the statistics.