Fast Convergence of DETR with Spatially Modulated Co-Attention

Peng Gao, Minghang Zheng, Xiaogang Wang, Jifeng Dai, Hongsheng Li

Abstract

The recently proposed Detection Transformer (DETR) model successfully applies Transformer to objects detection and achieves comparable performance with two-stage object detection frameworks, such as Faster-RCNN. However, DETR suffers from its slow convergence. Training DETR from scratch needs 500 epochs to achieve a high accuracy. To accelerate its convergence, we propose a simple yet effective scheme for improving the DETR framework, namely Spatially Modulated Co-Attention (SMCA) mechanism. The core idea of SMCA is to conduct location-aware co-attention in DETR by constraining co-attention responses to be high near initially estimated bounding box locations. Our proposed SMCA increases DETR’s convergence speed by replacing the original co-attention mechanism in the decoder while keeping other operations in DETR unchanged. Furthermore, by integrating multi-head and scale-selection attention designs into SMCA, our fully-fledged SMCA can achieve better performance compared to DETR with a dilated convolution-based backbone (45.6 mAP at 108 epochs vs. 43.3 mAP at 500 epochs).

Introduction

While traditional object detectors rely on complex, hand-engineered steps like anchor generation and Non-Maximum Suppression (NMS), DETR simplified the pipeline into an end-to-end transformer problem. However, DETR has a "search" problem: in the decoder, object queries have no initial idea where to look in the image. They must learn through hundreds of epochs of trial and error which spatial features correspond to which bounding boxes. This lack of spatial "common sense" makes DETR's convergence extremely slow compared to traditional detectors (500 epochs vs. 40 epochs). The authors aim to bridge this gap by providing the model with a dynamic, learnable spatial constraint.

Methodology

The core innovation is the Spatially Modulated Co-Attention (SMCA) mechanism. Instead of allowing the decoder's co-attention to look globally at the entire feature map with equal priority, SMCA constrains the search space using dynamic spatial weight maps. For every object query, the model predicts an initial center and scale, which are used to generate a 2D Gaussian-like weight map. This map is element-wise multiplied with the standard co-attention map, forcing the model to prioritize features near the predicted object location while suppressing background noise.

The proposed SMCA-DETR architecture featuring Spatially Modulated Co-Attention and a Scale Selection Network.

To capture complex shapes, each attention head can predict its own unique spatial offset and scale. Furthermore, the architecture integrates multi-scale features through an efficient encoder design using Intra-scale Self-Attention and a Scale Selection Network in the decoder that allows each query to adaptively pick the most relevant feature resolution.

Experimental Results

The authors evaluated their method on the COCO 2017 detection dataset. The results demonstrate a massive leap in training efficiency. SMCA achieves 43.7 mAP in just 50 epochs, whereas the original DETR requires 500 epochs to reach a lower 43.3 mAP.

Comparison of convergence curves between SMCA and DETR-DC5 on the COCO dataset.

As shown in the convergence plot, the full SMCA model reaches 45.6 mAP at 108 epochs, significantly outperforming the baseline DETR-DC5. While the inference time increases slightly (from 0.079s to 0.100s per image), the nearly 10x reduction in training time makes the model far more accessible for researchers with limited GPU resources.

Conclusion

SMCA demonstrates that guided search is superior to random search in transformer-based detection. By imposing a soft spatial prior, the model learns the relationship between features and boxes much faster without losing the benefits of the transformer architecture. As a plug-and-play module that only modifies the co-attention mechanism, SMCA offers a highly portable improvement for the DETR framework, achieving state-of-the-art efficiency in end-to-end object detection.

Summary updated

BibTeX
@inproceedings{gao2021fast,
  author = {Peng Gao and Minghang Zheng and Xiaogang Wang and Jifeng Dai and Hongsheng Li},
  title = {{Fast Convergence of DETR with Spatially Modulated Co-Attention}},
  booktitle = {IEEE/CVF International Conference on Computer Vision},
  year = {2021},
  url = {https://openreview.net/forum?id=eQlS9-DH6J0},
}
Figure