CNN-transformer mixed model for object detection

Wenshuo LiarXiv 2022 · DOI

Abstract

This paper proposes a hybrid "Conv-transformer" module that integrates into the YOLOv5n backbone to combine the local feature extraction of CNNs with the global context of Transformers. By downsampling feature maps before applying self-attention, the model achieves a 1.7% mAP improvement on the COCO dataset while maintaining a remarkably small footprint of just 3 million parameters—less than one-twentieth the size of traditional models like Faster R-CNN.

What Problem Does This Paper Address?

In the field of computer vision, Convolutional Neural Networks (CNNs) have long been the dominant architecture due to their "locality" — their ability to identify textures and patterns in small pixel neighborhoods. However, CNNs struggle to capture the "big picture" or the relationship between distant objects in an image.

Traditional two-stage object detection architectures like Faster R-CNN are significantly more complex and parameter-heavy than the proposed hybrid model.

Vision Transformers (ViTs) addressed this by using self-attention to look at the entire image simultaneously. However, Transformers are computationally expensive, with complexity growing quadratically with the number of pixels. This makes them difficult to deploy on standard hardware or use for high-resolution object detection. The author seeks to bridge this gap: obtaining the global "brain" of a Transformer without the massive computational "headache" of traditional heavyweights like Faster R-CNN.

Methods: The Conv-Transformer Block

The author introduces a novel Conv-transformer block designed to be integrated into the YOLOv5n architecture. The module functions as a clever "sandwich" of operations:

  1. Convolutional Downsampling: To avoid the quadratic complexity trap, the module first uses a convolution layer (with Batch Normalization and SiLU activation) to shrink the feature map size (e.g., from 80x80 to 20x20).
  2. Simplified Transformer Block: The downsampled map is flattened and fed into a Transformer layer. To maintain a lightweight profile, the author utilized 4 attention heads (instead of the standard 12) and a single repetition of the stack.
  3. Upsampling & Fusion: The global features are then scaled back up to the original size and concatenated with the initial input features.
  4. Final Convolution: A final layer fuses these local and global features together, ensuring the network benefits from both perspectives.

By placing this module at the end of the YOLOv5n network, the model gains a "global perspective" just before making its final detections.

Datasets and Evaluation

The model was evaluated using two industry-standard benchmarks to ensure robustness:

  • MS COCO: A massive dataset with 80 object categories. The author used the full dataset for training and COCO128 for initial sanity testing.
  • Pascal VOC: A more lightweight dataset with 20 categories, used to demonstrate the model's performance through migration learning (fine-tuning).

Key Insights and Ideas

  • The "Unsaturated" Curve: One of the most interesting findings was that after 300 epochs of training on COCO, the mAP (mean Average Precision) curve was still trending upward. Unlike pure CNNs, which often plateau early, the hybrid model suggested it had more "room to grow" if given more training time.
  • Efficiency via Downsampling: The paper demonstrates that you don't need to run self-attention on high-resolution maps to get the benefits. Downsampling to a 20x20 grid provides enough context to improve detection without exploding the parameter count.
  • Parameter David vs. Goliaths: The resulting model is tiny (3M parameters). When compared to Faster R-CNN using a ResNet101 backbone, the author's model achieved a higher mAP on Pascal VOC (81% vs 76.4%) despite being a fraction of the size.

Key Results

The hybrid model reached an mAP of 47.4 on the COCO dataset, representing a 1.7% improvement over the baseline YOLOv5n. On Pascal VOC, the model achieved 81% mAP after 100 rounds of training.

Object detection results across various categories using the hybrid Conv-transformer model.

The total parameter count is approximately 3 million, making it highly suitable for edge devices or applications where memory is a constraint. On Pascal VOC, it outperformed Faster R-CNN (vgg16) by 7.8% mAP and Faster R-CNN (resnet101) by 4.6% mAP, while using significantly fewer parameters.

Limitations and Future Work

The author is transparent about the constraints faced during this research:

  • Simplified Transformer: Due to hardware limitations (training on a single Tesla P100), the Transformer component was heavily simplified. A deeper Transformer stack would likely yield even better results.
  • Placement: The module was only added to the end of the network. Future work could involve integrating Conv-transformer blocks into other parts of the architecture, such as the PAN (Path Aggregation Network).
  • Training Time: The author noted that the COCO dataset is so large that the model was likely under-trained; more compute time would be needed to find the true performance ceiling of this hybrid approach.

Summary updated

BibTeX
@misc{li2022cnn,
  author = {Wenshuo Li},
  title = {{CNN-transformer mixed model for object detection}},
  year = {2022},
  eprint = {2212.06714},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2212.06714},
}
Figure