Linear Attention Mechanism: An Efficient Attention for Semantic Segmentation

Rui Li, Jianlin Su, Chenxi Duan, Shunyi Zheng

Introduction

Standard dot-product attention mechanisms, popularized by Transformers, are highly effective at capturing long-range dependencies in data. However, they suffer from a significant drawback: computational and memory costs grow quadratically $O(N^2)$ relative to the input size $N$. For high-resolution remote sensing images or long video sequences, this quadratic bottleneck often exceeds the memory limits of modern GPUs.

This paper introduces the Linear Attention Mechanism (LAM), which reduces this complexity to linear $O(N)$. By utilizing a first-order Taylor expansion to approximate the softmax function, the authors enable efficient high-resolution semantic segmentation without sacrificing accuracy.

Methodology

The LAM module achieves efficiency through three primary mathematical innovations:

  1. Taylor Approximation: The standard attention mechanism uses a $softmax$ function to calculate similarities between Queries ($Q$) and Keys ($K$). LAM replaces the exponential term in the softmax ($e^{q_i^T k_j}$) with a first-order Taylor expansion: $1 + q_i^T k_j$.
  2. Normalization for Stability: To prevent negative values and ensure numerical stability, $L_2$ normalization is applied to the Query and Key vectors.
  3. Associative Property Optimization: In standard attention, $Q$ and $K^T$ are multiplied first, creating a massive $N \times N$ matrix. In the Linear Attention formulation, the associative property of matrix multiplication allows for multiplying $K^T$ and $V$ (the Values) first. This results in a much smaller matrix (feature dimension $\times$ feature dimension) that is independent of the number of pixels $N$.

This module is designed to be "plug-and-play," allowing it to be integrated into existing architectures like U-Net or DeepLab to provide global context at a fraction of the original computational cost.

Dataset and Experimental Setup

The researchers evaluated LAM using the Fine Gaofen Image Dataset (GID), which consists of high-resolution RGB images captured by the Gaofen 2 Satellite. The dataset includes 15 distinct land-cover categories, such as industrial land, paddy fields, and various water bodies.

Visual samples from the Fine GID dataset showing satellite imagery and corresponding ground truth segmentation masks.

For the experiments, the high-resolution images were partitioned into 7,280 patches of $256 \times 256$ pixels for training, validation, and testing.

Key Results

The authors benchmarked LAM across seven different baseline architectures. In every instance, the addition of the Linear Attention Mechanism improved key performance metrics, including Mean Intersection over Union (mIoU) and F1-score.

Experimental results on the Fine GID dataset comparing baseline models against versions enhanced with LAM.

Notable improvements include:

  • U-Net: mIoU increased from 64.52% to 68.04%.
  • DeepLabV3+: mIoU increased from 72.67% to 73.73%.
  • RefineNet: mIoU increased from 73.17% to 74.97%.
  • FastFCN: mIoU increased from 74.36% to 75.17%.

These results demonstrate that LAM is not only more efficient but also enhances model performance by enabling the inclusion of global context that was previously too computationally expensive to process.

Discussion and Limitations

The primary strength of LAM is its ability to decouple computational complexity from image resolution, making the mechanism "resolution-agnostic" regarding scaling. However, some limitations remain. The study focuses exclusively on remote sensing data; further research is needed to compare this Taylor-approximation approach against other linear attention variants (like Performer or Linformer) on standard computer vision benchmarks such as Cityscapes or ADE20K. Additionally, while the theoretical complexity is reduced, more empirical data on actual wall-clock training time speedups would be beneficial for practical implementation.

Summary updated

Abstract

In this paper, to remedy this deficiency, we propose a Linear Attention Mechanism which is approximate to dot-product attention with much less memory and computational costs. The efficient design makes the incorporation between attention mechanisms and neural networks more flexible and versatile. Experiments conducted on semantic segmentation demonstrated the effectiveness of linear attention mechanism. Code is available at https://github.com/lironui/Linear-Attention-Mechanism.
BibTeX
@misc{li2020linear,
  author = {Rui Li and Jianlin Su and Chenxi Duan and Shunyi Zheng},
  title = {{Linear Attention Mechanism: An Efficient Attention for Semantic Segmentation}},
  year = {2020},
  eprint = {2007.14902},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2007.14902},
}
Figure