EHNet: An Efficient Hybrid Network for Crowd Counting and Localization

Yuqing Yan, Yirui WuarXiv 2025 · DOI

Abstract

Crowd counting and localization in dense urban environments remain challenging due to extreme scale variations and the need for real-time processing. EHNet (Efficient Hybrid Network) addresses these issues by combining the global modeling capabilities of Transformers with the local feature extraction of CNNs. By utilizing a point regression framework and a lightweight architecture of only 2.5 million parameters, EHNet achieves state-of-the-art performance on major benchmarks while maintaining high inference speeds suitable for edge deployment.

Introduction

Estimating the number of individuals in a dense image is a critical task for public safety and urban planning. However, models often struggle with the "global vs. local" trade-off. CNN-based models excel at local patterns but lack long-range context, while Transformer-based models capture global relationships at a high computational cost. EHNet bridges this gap with a hybrid approach designed for efficiency and precision.

Methodology

EHNet is built on an encoder-decoder framework optimized for both counting accuracy and localization precision.

The overall EHNet pipeline, consisting of a VGG16-BN encoder and a Multi-Scale Attentive Decoder (MSAD).

Point Regression Framework

Unlike traditional methods that generate blurry density maps, EHNet employs a point regression framework. It predicts specific anchor point offsets and confidence scores, allowing the model to pinpoint the exact coordinates of individuals rather than just estimating a total count. This approach is critical for applications requiring precise spatial awareness.

Spatial-Position Attention Module (SPAM)

The core of the MSAD decoder is the SPAM module, which processes features in parallel to maintain both global context and local detail.

The Spatial-Position Attention Module (SPAM) utilizes a three-branch parallel structure to capture global and local features.

As shown in the diagram, SPAM consists of three branches:

  1. Transformer Block: Captures global context and long-range dependencies.
  2. Convolution Branch: Extracts fine-grained local spatial features.
  3. Cipherbook (Codebook) Module: Uses a learned dictionary (Key-Value pairs) to identify explicit spatial patterns.

Adaptive Feature Aggregation Module (AFAM)

To handle multi-scale features, EHNet uses the AFAM module. This component employs RepConv, a structural re-parameterization technique. During training, it uses multiple paths to learn robust features; during inference, these paths are mathematically collapsed into a single, high-speed convolution, significantly reducing latency without sacrificing accuracy.

Experimental Results

EHNet was evaluated on standard benchmarks including ShanghaiTech (Part A & B), UCF-CC-50, and UCF-QNRF.

Accuracy and Localization

On ShanghaiTech Part A, EHNet achieved a Mean Absolute Error (MAE) of 50.29, outperforming significantly larger models like M2PLNet. More impressively, in localization tasks, it reached an F1-score of 52.13%, representing a 9-percentage-point improvement over the previous state-of-the-art method, P2PNet.

Efficiency

The model's efficiency is its standout feature. While competing models often exceed 500 million parameters, EHNet uses only 2.5 million. This translates to a self-CPU inference time of just 5.3ms, making it ideal for real-time deployment on devices where GPU resources may be limited.

Conclusion

EHNet demonstrates that high-performance crowd counting does not require massive computational overhead. By intelligently combining CNN and Transformer architectures in a parallel, lightweight decoder, EHNet provides a scalable solution for real-world localization and counting tasks. Future research will explore extending this hybrid architecture to video-based counting to improve temporal consistency across frames.

Summary updated

BibTeX
@misc{yan2025ehnet,
  author = {Yuqing Yan and Yirui Wu},
  title = {{EHNet: An Efficient Hybrid Network for Crowd Counting and Localization}},
  year = {2025},
  eprint = {2503.12061},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2503.12061},
}
Figure