Sparse DETR: Efficient End-to-End Object Detection with Learnable Sparsity

Byungseok Roh, Jaewoong Shin, Wuhyun Shin, Saehoon Kim

TL;DR

Sparse DETR introduces a learnable token sparsification mechanism that selectively updates only the most "important" encoder tokens in a transformer-based object detector. By focusing computation on just 10% of encoder tokens, the model achieves better accuracy than Deformable DETR while reducing total computational cost by 38% and boosting inference speed (FPS) by 42%.

Attention patterns across DETR variants

What Problem Does This Paper Address?

The original DETR (Detection Transformer) revolutionized object detection by removing the need for hand-crafted components like Non-Maximum Suppression (NMS). However, it struggled with small objects and slow convergence. Its successor, Deformable DETR, solved these issues by using multi-scale feature maps and sparse attention.

But there was a catch: using multi-scale features increased the number of encoder tokens by 20x. In these models, the transformer encoder becomes a massive computational bottleneck. The authors observed that in a typical image, a huge portion of these tokens represent irrelevant background. If the decoder only ends up "looking" at a fraction of these tokens to make its final predictions, why spend heavy computation updating all of them?

Methods

Sparse DETR introduces Learnable Sparsity to the encoder. Instead of updating every single token through every encoder layer, it identifies a salient subset of tokens to process.

Sparse DETR Architecture

Key components of the architecture include:

  • Encoder Token Sparsification: The model uses a scoring network to rank tokens. Only the top-$\rho$% (e.g., 10% or 20%) are updated by the encoder layers. The unselected tokens are simply passed through without extra computation, though they can still be "seen" by the selected ones.
  • Saliency Criteria: The authors compared two ways to pick tokens:
  • Objectness Score (OS): Using a lightweight head to predict if a token belongs to the foreground.
  • Decoder cross-Attention Map (DAM): A novel approach where a scoring network learns to predict which tokens the decoder will eventually want to attend to. This "decoder-centric" view proves more effective than simple foreground detection.
  • Encoder Auxiliary Loss: To make the sparse training stable, the authors apply a detection loss directly to the selected encoder tokens. This helps the model learn better features early on and prevents vanishing gradients in deep encoders.
  • Top-k Decoder Queries: Instead of using fixed learnable queries, the model selects the best tokens from the encoder output to initialize the decoder, further aligning the encoder and decoder.

Datasets

The model was trained and evaluated on the COCO 2017 object detection benchmark, a standard in the field. The authors tested their approach across several backbones, including ResNet-50, Swin-Tiny, and Swin-Base.

Key Insights and Ideas

  • The 45% Observation: The authors found that in a fully trained Deformable DETR, the decoder only references about 45% of encoder tokens. This confirmed that the encoder is doing a lot of "wasted" work on background regions.
  • DAM > OS: Interestingly, picking tokens based on what the decoder wants (DAM) works better than picking tokens that look like objects (OS). This suggests that some "background" tokens might actually provide crucial context for the decoder to refine its bounding boxes.
  • Efficiency Enables Depth: Because the sparse encoder is so much lighter, the authors were able to stack more encoder layers (up to 12) within the same computational budget, leading to even higher accuracy.
  • Vanishing Gradient Fix: They discovered that deep DETR encoders often fail to converge because gradients from the decoder vanish. The proposed auxiliary loss on sparse tokens acts as a "shortcut" for gradients, making deep architectures viable.

Key Results

Sparse DETR consistently outperforms Deformable DETR while being significantly faster:

  • Efficiency: Using only 10% of encoder tokens, Sparse DETR achieves 48.2 AP (Average Precision) on COCO with a Swin-T backbone, surpassing the 48.0 AP of the dense baseline.
  • Speedup: For the ResNet-50 version, Sparse DETR reduces total GFLOPs by 38% and increases throughput from 18.2 to 25.3 FPS (a 42% improvement).
  • Scalability: When scaled up to a Swin-B backbone, Sparse DETR achieves a massive 53.3 AP, showing that the sparsification logic holds up even with very high-capacity models.

Limitations and Future Work

  • Backbone Sparsity: This paper focuses specifically on the Transformer encoder/decoder bottleneck. It does not sparsify the initial backbone (e.g., the ResNet or Swin stages), which still accounts for a portion of the total cost. The authors note their work is orthogonal to backbone sparsification and could likely be combined with it.
  • Dynamic Ratios: While the model can adapt to different sparsity ratios at inference time, the authors suggest that "dynamic ratio training" (training one model to handle any ratio) could be a promising area for future exploration to make the model even more robust across different hardware constraints.

Summary updated

BibTeX
@inproceedings{roh2022sparse,
  author = {Byungseok Roh and Jaewoong Shin and Wuhyun Shin and Saehoon Kim},
  title = {{Sparse DETR: Efficient End-to-End Object Detection with Learnable Sparsity}},
  booktitle = {International Conference on Learning Representations},
  year = {2022},
  url = {https://openreview.net/forum?id=Z9LkhsFBBI_},
}
Figure