Counting Varying Density Crowds Through Density Guided Adaptive Selection CNN and Transformer Estimation

Yuehai Chen, Jing Yang, Badong Chen, Shaoyi Du · DOI

Abstract

In real-world crowd counting applications, the crowd densities in an image vary greatly. When facing density variation, humans tend to locate and count the targets in low-density regions, and reason the number in high-density regions. We observe that CNN focus on the local information correlation using a fixed-size convolution kernel and the Transformer could effectively extract the semantic crowd information by using the global self-attention mechanism. Thus, CNN could locate and estimate crowds accurately in low-density regions, while it is hard to properly perceive the densities in high-density regions. On the contrary, Transformer has a high reliability in high-density regions, but fails to locate the targets in sparse regions. Neither CNN nor Transformer can well deal with this kind of density variation. To address this problem, we propose a CNN and Transformer Adaptive Selection Network (CTASNet) which can adaptively select the appropriate counting branch for different density regions. Firstly, CTASNet generates the prediction results of CNN and Transformer. Then, considering that CNN/Transformer is appropriate for low/high-density regions, a density guided adaptive selection module is designed to automatically combine the predictions of CNN and Transformer. Moreover, to reduce the influences of annotation noise, we introduce a Correntropy based optimal transport loss. Extensive experiments on four challenging crowd counting datasets have validated the proposed method.

Introduction

Crowd counting is a critical task in computer vision with applications in public safety and urban planning. However, it remains deceptively difficult due to extreme scale and density variations within a single image. For instance, a single frame might contain a few clearly visible individuals in the foreground and thousands of tiny, overlapping heads in the background.

The challenge of varying crowd density and scale across different image regions.

Current architectures struggle with these extremes. Convolutional Neural Networks (CNNs) excel at capturing local patterns, making them effective for "locating" individuals in sparse areas. However, they often fail in dense regions where heads are only a few pixels wide. Conversely, Transformers utilize global self-attention to "reason" about the overall crowd volume in dense areas but lack the local precision needed for sparse regions. No single architecture handles both extremes perfectly, and human-annotated data is often "noisy," further complicating training.

Methods: The CTASNet Architecture

To bridge this gap, we propose the CNN and Transformer Adaptive Selection Network (CTASNet). The architecture is designed around three core components:

  • Dual-Branch Estimation: The network processes images through parallel CNN and Transformer branches. The CNN branch employs Atrous Spatial Pyramid Pooling (ASPP) for multi-scale local features, while the Transformer branch leverages self-attention for global semantic understanding.
  • Adaptive Selection Module (ASM): Acting as a central controller, the ASM analyzes the density of image patches to generate an attention map. This map adaptively weights the contributions of each branch—favoring the CNN for sparse regions and the Transformer for dense ones.
  • Correntropy-based Optimal Transport (COT) Loss: Standard training losses often penalize minor annotation offsets (noise) too severely. By introducing a loss based on correntropy, CTASNet becomes more robust to the "jitter" inherent in human-provided head annotations.

Key Insights and Results

The fundamental philosophy behind CTASNet is mimicking human perception: we "locate" in sparse areas and "reason" in dense ones. Qualitative analysis of the attention maps reveals that CNNs produce sharp, accurate points in sparse zones but struggle with background noise. Transformers, meanwhile, provide a more accurate, albeit "smeared," density estimation in highly congested areas.

Comparison of CNN (VGG) and Transformer attention maps. Note how VGG focuses on sparse foreground regions (green) while the Transformer captures dense background regions (red) more effectively.

CTASNet was evaluated on four major benchmarks: ShanghaiTech (Parts A & B), UCF_CC_50, UCF-QNRF, and NWPU. The model achieved state-of-the-art (SOTA) or near-SOTA performance:

  • ShanghaiTech A: Achieved a record low Mean Squared Error (MSE) of 87.8.
  • UCF_CC_50: Improved the Mean Absolute Error (MAE) by 5.77% over previous methods.
  • Efficiency: The model maintains real-time performance, processing images in approximately 0.048 seconds on an NVIDIA 3090 GPU.

Conclusion

CTASNet successfully addresses the challenge of varying crowd densities by adaptively combining the strengths of CNNs and Transformers. While the model shows significant improvements, future work will focus on addressing underestimation in extremely dense regions (>400 people per patch) and optimizing the parameter overhead introduced by the Transformer branch.

Summary updated

BibTeX
@article{chen2022counting,
  author = {Yuehai Chen and Jing Yang and Badong Chen and Shaoyi Du},
  title = {{Counting Varying Density Crowds Through Density Guided Adaptive Selection CNN and Transformer Estimation}},
  journal = {IEEE Trans. Circuits Syst. Video Technol.},
  year = {2022},
  doi = {10.1109/tcsvt.2022.3208714},
}
Figure