Scene-Adaptive Attention Network for Crowd Counting

Xing Wei, Yuanrui Kang, Jihao Yang, Yunfeng Qiu, Dahu Shi, Wenming Tan, Yihong GongarXiv 2021

Abstract

Crowd counting is a challenging task due to extreme scale variations and complex scene layouts. Traditional methods often rely on rigid convolutional kernels or computationally expensive global attention mechanisms. This paper introduces the Scene-Adaptive Attention Network (SAANet), a flexible Transformer-based architecture. By employing a novel "Deformer" backbone with deformable attention, the model dynamically adjusts its receptive field and attention weights to match the scene's perspective. SAANet achieves state-of-the-art results, ranking first on the challenging NWPU-Crowd benchmark.

Introduction

Estimating the number of people in an image is complicated by perspective distortion, where individuals appear large in the foreground and significantly smaller in the background. Traditional Convolutional Neural Networks (CNNs) utilize fixed-size kernels that lack the adaptability required for such geometric variations. While dilated convolutions expand the receptive field, they remain structurally rigid. Recent Vision Transformers (ViTs) offer flexibility through self-attention but often face a trade-off between computational efficiency (fixed-size windows) and global context (quadratic complexity). SAANet bridges this gap by learning exactly where and how to sample features based on the unique geometry of the crowd.

Methodology

The SAANet architecture is built upon three primary innovations designed to enhance adaptability and efficiency:

1. Deformer Backbone

The core of SAANet is a hierarchical Transformer that utilizes Deformable Attention. Unlike standard self-attention which considers every pixel or a fixed window, deformable attention learns 2D offsets to sample a small, learned subset of "key" locations. This allows the network to "shape" its receptive field to match the crowd's perspective distortion—sampling more widely for large foreground objects and more densely for distant, tiny clusters. This sparsity makes the mechanism significantly more computationally efficient than global self-attention, as it attends to a small number of sampled keys rather than the entire image.

Comparison of different convolution and attention mechanisms. SAANet's deformable attention (f) allows for sparse, adaptive sampling compared to rigid or global methods.

2. Multi-Level Feature Fusion (MFF)

Crowd counting requires a balance of high-level semantic information (to identify crowd textures) and low-level spatial details (for precise localization). MFF employs deformable attention to efficiently fuse features across different stages of the backbone, ensuring that both coarse and fine-grained information are preserved. The model is trained using a combination of Distribution Matching Loss for density map estimation and an auxiliary Query Loss to supervise count regression.

3. Count-Attentive Feature Enhancement (CAFE)

The CAFE module uses a Transformer decoder with a learnable "count query." By analyzing the global image context, it generates attention maps that recalibrate features—amplifying foreground objects (people) while suppressing background noise such as trees or buildings. This module provides the model with a "sense" of the overall crowdedness, acting as a smart filter to reduce false positives.

Experiments and Results

SAANet was evaluated on several major benchmarks, including ShanghaiTech (Part A & B), UCF-QNRF, JHU-Crowd++, and NWPU-Crowd.

On the NWPU-Crowd benchmark, the largest and most challenging to date, SAANet achieved a Mean Absolute Error (MAE) of 66.0 and a Mean Squared Error (MSE) of 298.8, ranking No. 1 on the public leaderboard at the time of publication. It significantly outperformed previous CNN and Transformer-based methods. Qualitative results indicate that SAANet produces sharper and more accurately localized density maps compared to previous state-of-the-art methods like DM-Count, which often produce blurry estimations.

Conclusion

SAANet demonstrates that adaptability is crucial for handling the geometric complexities of crowd counting. By leveraging deformable attention, the model achieves high performance with greater computational efficiency than global Transformers. Future work may involve extending this scene-adaptive approach to video streams for temporal consistency and optimizing the architecture for real-time deployment on edge devices.

Summary updated

BibTeX
@misc{wei2021scene,
  author = {Xing Wei and Yuanrui Kang and Jihao Yang and Yunfeng Qiu and Dahu Shi and Wenming Tan and Yihong Gong},
  title = {{Scene-Adaptive Attention Network for Crowd Counting}},
  year = {2021},
  eprint = {2112.15509},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2112.15509},
}
Figure