Toward Transformer-Based Object Detection

Josh Beal, Eric Kim, Eric Tzeng, Dong Huk Park, Andrew Zhai, Dmitry KislyukarXiv 2020

Abstract: Transformers have become the dominant model in natural language processing, owing to their ability to pretrain on massive amounts of data, then transfer to smaller, more specific tasks via fine-tuning. The Vision Transformer was the first major attempt to apply a pure transformer model directly to images as input, demonstrating that as compared to convolutional networks, transformer-based architectures can achieve competitive results on benchmark classification tasks. However, the computational complexity of the attention operator means that we are limited to low-resolution inputs. For more complex tasks such as detection or segmentation, maintaining a high input resolution is crucial to ensure that models can properly identify and reflect fine details in their output. This naturally raises the question of whether or not transformer-based architectures such as the Vision Transformer are capable of performing tasks other than classification. In this paper, we determine that Vision Transformers can be used as a backbone by a common detection task head to produce competitive COCO results. The model that we propose, ViT-FRCNN, demonstrates several known properties associated with transformers, including large pretraining capacity and fast fine-tuning performance. We also investigate improvements over a standard detection backbone, including superior performance on out-of-domain images, better performance on large objects, and a lessened reliance on non-maximum suppression. We view ViT-FRCNN as an important stepping stone toward a pure-transformer solution of complex vision tasks such as object detection.

Introduction

Vision Transformers (ViTs) have revolutionized image classification, but their application to spatially-sensitive tasks like object detection remains an open question. Convolutional Neural Networks (CNNs) have long been the standard backbone for detection because they naturally preserve spatial hierarchies. This paper introduces ViT-FRCNN, a model that demonstrates how pure transformer backbones can be successfully adapted for complex vision tasks. By leveraging massive pretraining and global self-attention, ViT-FRCNN generalizes better to out-of-domain data and naturally produces fewer duplicate bounding boxes than traditional CNN-based detectors.

Methods

The core contribution is the ViT-FRCNN architecture, which integrates a Vision Transformer backbone with a standard Faster R-CNN head.

Architecture of ViT-FRCNN, showing the reshaping of transformer patch outputs into a 2D feature map for a Faster R-CNN detection head.

Instead of using a CNN to generate spatial feature maps, the model takes the output sequence from the final ViT layer (excluding the global class token) and spatially reshapes the 1D sequence of patch embeddings back into a 2D feature map. This map is then passed through standard residual blocks to reduce dimensionality before entering a conventional Region Proposal Network (RPN) and RoI pooling mechanism. To accommodate the high-resolution inputs required for detection, the authors employ bilinear interpolation of the ViT's learned positional embeddings at runtime to match the larger input sizes.

Datasets and Evaluation

The models were pretrained on large-scale datasets, including ImageNet-21k and a massive internal Pinterest dataset containing 1.3 billion weakly-supervised images (Annotations-1.3B). Fine-tuning was conducted on the COCO 2017 benchmark, with additional out-of-distribution (OOD) evaluation on ObjectNet-D, a subset of ObjectNet designed to test robustness against real-world domain shifts like unusual rotations and viewpoints.

Key Results and Insights

COCO AP performance across varying NMS overlap thresholds, highlighting ViT-FRCNN's reduced reliance on duplicate suppression compared to ResNet baselines.
  • Spatial Awareness: Despite computing attention globally, ViT patch embeddings retain sufficient local spatial correspondence for accurate localization.
  • Resolution Sensitivity: Reducing patch size from 32x32 to 16x16 yielded a +6.9 AP boost on COCO, emphasizing the importance of fine-grained resolution for transformer-based detectors.
  • Natural Duplicate Suppression: ViT-FRCNN relies significantly less on Non-Maximum Suppression (NMS). At an NMS threshold of 0.95 (where suppression is nearly disabled), the ViT-B/16* model outperformed a ResNet101 baseline by 8.1 AP. This suggests that global attention allows features to "attend" to each other, helping the model realize when an object has already been detected.
  • OOD Robustness: On ObjectNet-D, ViT-B/16* achieved 22.9 AP, significantly outperforming the ResNet101 baseline (15.9 AP), demonstrating superior robustness to domain shifts.

Conclusion

While ViT-FRCNN shows great promise, it does not yet surpass heavily optimized CNN-FPN baselines on COCO. High-resolution processing with small patches also presents significant computational and memory challenges. Future work will explore the mechanisms behind the transformer's natural duplicate suppression and scaling pretraining to further bridge the performance gap. ViT-FRCNN serves as a critical stepping stone toward pure-transformer solutions for complex computer vision tasks.

Summary updated

BibTeX
@misc{beal2020toward,
  author = {Josh Beal and Eric Kim and Eric Tzeng and Dong Huk Park and Andrew Zhai and Dmitry Kislyuk},
  title = {{Toward Transformer-Based Object Detection}},
  year = {2020},
  eprint = {2012.09958},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2012.09958},
}
Figure