[KongchangAI]
· 2 min read· 1,495 words

CanopyFormer: Attention-Guided Interpretable Forest Cover Segmentation

CanopyFormer: Attention-Guided Interpretable Forest Cover Segmentation

CanopyFormer supervises segmentation attention to focus on canopy, boosting interpretability but questioning faithfulness.

CanopyFormer is an attention-guided SegFormer-B0 that aligns encoder attention with forest masks using an attention consistency loss, turning attention into explicit supervision. Adapted gradient-weighted attention rollout and the AAMO metric raise alignment from 0.0334 to 0.7476 (~22x) with Dice only dropping from 0.8743 to 0.8577. Deletion tests reveal a paradox: removing the top 25% attended patches drops the score 12.1%, versus 33.0% for random removal, so alignment does not fully equal faithfulness.

Title

CanopyFormer: Attention-Guided Interpretable Forest Cover Segmentation

Meta Description

CanopyFormer proposes an attention-guided SegFormer-B0 that aligns with forest masks via an attention consistency loss, boosting AAMO by ~22x with only a slight Dice drop. Deletion tests reveal a paradox between attention alignment and faithfulness; training cost increases but inference has no extra overhead.

Article Content

Attention mechanisms in Transformer segmentation models are typically only visualized after training, but CanopyFormer turns them into a supervision signal. This paper from arXiv proposes an attention-guided variant of SegFormer-B0 that uses an attention consistency loss to make the model focus on canopy regions, improving interpretability at only a slight cost in accuracy.

CanopyFormer paper title screenshot

How Attention Supervision Works

The core of CanopyFormer is an Attention Consistency Loss. In standard SegFormer, attention maps are merely a byproduct inside the encoder, but here they are directly aligned with ground-truth forest masks, forcing attention to focus on the canopy. Because SegFormer uses spatial-reduction attention, standard attention rollout methods cannot be applied directly. The authors adapt Gradient-weighted Attention Rollout, restricting it to the final stage of the encoder, where the attention matrices are square.

To quantify the degree of attention alignment, the paper proposes the Average Attention-Mask Overlap (AAMO) metric. On a dataset of 5,108 images, AAMO rises from 0.0334 for the baseline SegFormer-B0 to 0.7476—roughly 22 times higher—while the Dice score drops only from 0.8743 to 0.8577. This trade-off shows that attention supervision can substantially improve interpretability with almost no sacrifice in segmentation quality.

Spatial-Reduction Attention is an attention variant used in the SegFormer encoder to reduce computational complexity. Standard self-attention computes the similarity between each token and all tokens, with complexity growing quadratically with image resolution; spatial-reduction attention first downsamples the feature map convolutionally before computing keys and values, reducing the number of tokens involved in attention by a ratio factor and thus bringing complexity down to roughly linear. The cost is that the attention matrix is no longer square—there are more queries than keys/values, which is exactly why the paper says "standard attention rollout methods cannot be applied directly." This is also why the authors apply gradient-weighted attention rollout only to the final encoder stage: there the spatial-reduction ratio is set to 1, the attention matrix becomes square again, and the rollout operation has clear mathematical meaning. Understanding this is necessary to see why attention supervision requires extra adaptation work on this architecture rather than simply using off-the-shelf tools.

Gradient-weighted Attention Rollout is a common technique for aggregating multi-layer attention into a single explanation map. Each Transformer layer has its own attention matrix, and simple summation ignores information mixing between layers; attention rollout approximates the influence path from input tokens to the final output by normalizing and multiplying attention matrices as they propagate across layers. Gradient weighting further introduces the gradient of the output with respect to the attention maps, using gradient magnitude to measure the importance of each attention head and then summing them in a weighted manner, thereby suppressing heads irrelevant to the decision. The method was originally used for classification tasks in Vision Transformer, and this paper transfers it to segmentation while restricting it to a single stage—an adaptation of an existing explanation tool rather than a wholly new invention. This also means that the AAMO metric's values depend heavily on the assumptions of the rollout method itself, so cross-architecture comparisons should be made with caution.

The Paradox of Faithfulness: Good Alignment Does Not Equal Faithfulness

Despite the large improvement in AAMO, deletion tests reveal a more subtle conclusion. Deletion tests evaluate whether attention truly reflects the basis of decisions by removing the image patches the model focuses on most. After removing the top 25% most-attended patches, the forest score drops by 12.1%; randomly removing the same proportion of patches drops the score by 33.0%. This indicates that the regions the model attends to are indeed important, but improvements in attention alignment do not fully translate into improved faithfulness—because random removal is actually more destructive.

This finding challenges the intuition that "better attention alignment means more faithful explanations." The authors argue that the deletion test results show that although attention supervision makes attention maps look more consistent with human expectations, the model may still be using other unattended regions to make decisions. Interpretability research needs to consider both alignment and faithfulness dimensions.

The Deletion Test is a classic perturbation method for evaluating explanation faithfulness. Its basic logic is: if an image region is judged important by an explanation method, then removing it from the input should significantly change the model output; conversely, removing regions judged unimportant should leave the output largely unchanged. In practice, image patches are usually deleted progressively in order of importance, and a curve of model score versus deletion ratio is plotted—the faster the curve drops, the more faithful the explanation. This paper compares removing the top 25% most-attended patches with randomly removing 25% of patches: if attention truly reflects the basis of decisions, the former should cause a markedly larger score drop than the latter. The result is the opposite—random removal is more destructive (33.0% vs. 12.1%), indicating that the regions the model attends to most are not the sole basis for its decisions, and the attention map may capture only part of the cues. This paradox suggests that alignment metrics (such as AAMO) measure "whether attention looks where humans expect," while deletion tests measure "whether the model actually relies on the regions it looks at"—the two are not substitutes for each other.

Training Cost and Generalization

Attention supervision does not add inference cost, but during training, because double backpropagation is required, each training step becomes 2.6 to 2.8 times slower. This is a real cost that must be weighed. The good news is that improvements in attention alignment generalize to a second dataset, LoveDA, showing that the method does not depend on a specific data distribution.

In addition, the paper explores a Boundary Refinement Module but finds that it does not bring consistent Dice improvements and instead lowers AAMO. As for the choice of attention loss function, mean squared error (MSE) is significantly better than Kullback-Leibler divergence (KL divergence). These ablation experiments provide clear engineering guidance for future research.

Double Backpropagation refers to performing two backward passes in a single training step: one to compute the gradient of the main segmentation loss, and another to compute the gradient of the attention consistency loss with respect to the attention maps, which is exactly what gradient-weighted attention rollout requires. Ordinary training needs only one backward pass to update parameters, whereas attention supervision requires first differentiating through the attention maps to obtain weights, then using those weights in the alignment loss, so the computation graph must retain longer paths, increasing both memory usage and computation time. The paper reports a 2.6 to 2.8 times slowdown per step, mainly from the second backward pass and the intermediate activations retained for the rollout operation. Notably, this cost exists only during training; at inference time, attention maps can be obtained directly as a byproduct of the forward pass with no additional latency, so for remote sensing application scenarios where training resources are relatively abundant but deployment-side compute is constrained, this trade-off is acceptable.

Significance for Forest Monitoring

Forest cover segmentation is a fundamental task in remote sensing applications, involving carbon stock estimation, biodiversity monitoring, and more. The value of CanopyFormer lies in making the model's decision process more transparent—when the model determines that a region is forest, the attention map can clearly indicate which canopy features it relies on. This is especially important for environmental monitoring scenarios that require trustworthy AI.

Of course, the disconnect between attention alignment and faithfulness also reminds us that interpretability cannot be judged solely by visually pleasing attention maps. Future work may need to combine multiple explanation methods and validate the effectiveness of explanations in real decision-making tasks.

One-line Summary

CanopyFormer uses an attention consistency loss to supervise a segmentation model to focus on canopy, greatly improving interpretability but raising questions about faithfulness.

Paragraph Summary

CanopyFormer is an attention-guided variant of SegFormer-B0 that aligns encoder attention maps with ground-truth forest masks via an attention consistency loss, turning attention from a post-training visualization byproduct into an explicit supervision signal. Because SegFormer uses spatial-reduction attention, the authors adapt gradient-weighted attention rollout and apply it only to the final encoder stage, and they propose the AAMO metric to quantify alignment. On 5,108 images, AAMO rises from 0.0334 to 0.7476 (~22x), while Dice drops only from 0.8743 to 0.8577. But deletion tests reveal a paradox: removing the top 25% most-attended patches drops the score by 12.1%, while random removal drops it by 33.0%, showing that improved alignment does not fully translate into faithfulness. Training is 2.6-2.8x slower per step due to double backpropagation, inference has no extra cost, and it generalizes to LoveDA. Ablations show the boundary refinement module is ineffective and MSE outperforms KL divergence.

#CanopyFormer#SegFormer-B0#attention consistency loss#forest cover segmentation#attention rollout#interpretability#deletion test#remote sensing
Share:

Related articles