In transformer segmentation models, attention is usually visualized after training rather than supervised. Although attention supervision has been explored for natural images and driving scenes, aerial forest segmentation typically uses attention only as an architectural component and evaluates interpretability qualitatively. We present CanopyFormer, an attention-guided SegFormer-B0 that uses an Attention Consistency Loss to align attention with the ground-truth forest mask, encouraging attention to focus on canopy regions. Since SegFormer uses spatial-reduction attention, we adapt Gradient-weighted Attention Rollout by restricting it to the final encoder stage, where the attention matrix is square. We introduce Average Attention-Mask Overlap (AAMO) to measure attention alignment and incorporate a deletion test to evaluate faithfulness. On 5108 images, our method increases AAMO from 0.0334 to 0.7476, approximately 22 times the vanilla SegFormer-B0 result, with a modest decrease in Dice score from 0.8743 to 0.8577. The deletion test reveals that improved alignment does not necessarily translate into improved faithfulness: removing the most-attended 25% of patches reduces the forest score by 12.1%, compared with 33.0% when removing random patches. Attention supervision introduces no additional inference cost, although double backpropagation makes each training step 2.6 to 2.8 times slower. The attention alignment improvement also generalizes to a second dataset, LoveDA. Additionally, a Boundary Refinement Module provides no consistent Dice improvement and reduces AAMO, while mean squared error substantially outperforms Kullback-Leibler divergence as the attention loss.
Figures & tables
Method
Attention target
Architecture
Domain / task
Explanation method
Evaluation metric
ForResANeXt [ 4 ]
None (architectural)
CNN + attention
Satellite forest seg.
None
Segmentation metrics
PP-LiteSeg [ 5 ]
None (architectural)
CNN + attention
UAV forest seg.
None
Segmentation metrics
Attention U-Net [ 6 ]
None (architectural)
CNN + attention gates
Sentinel-2 deforestation
None
Segmentation metrics
Mahakalanda et al. [ 13 ]
None
CNN (FCN-8, U-Net)
Sentinel-2 rubber
None
Accuracy, IoU, Dice
Meedeniya et al. [ 14 ]
None
Mask R-CNN
Sentinel-2 paddy
None
Average precision
Attention Rollout [ 11 ]
None (post-hoc)
Transformer
Natural language
Rollout / flow
Agreement with ablation
TABLE I: Comparison with the closest land-cover, attention-supervision, and explainability work.
Fig. 2: Gradient-weighted attention rollout on SegFormer stage 4.
Model
Dice
IoU
F1
AAMO
Params
U-Net (CNN)
0.8615
0.7568
0.8615
n/a
31.0 M
DeepLabV3+ (MNetV3)
0.8716
0.7724
0.8716
n/a
11.0 M
SegFormer-B2
0.8809
0.7872
0.8809
n/a
27.3 M
Swin-T + UPerNet
0.8793
0.7847
0.8793
n/a
58.9 M
SegFormer-B0
0.8743
0.7766
0.8743
0.0334
3.7 M
+ Latt (MSE), CanopyFormer
0.8577
0.7508
0.8577
0.7476
3.7 M
TABLE II: Test results (seed 42, shared 766-image test set). The KL row changes only the form of Latt .
Fig. 3: Alignment against accuracy for the SegFormer-B0 variants.
School of Electronic Science and Engineering, Nanjing University, Nanjing, 210023, China · TopXGun Robotics, Nanjing, 211100, China · School of Computer Science, Nanjing University of Posts and Telecommunications, Nanjing, 210023, China +1