Abstract
Object counting in "low-shot" scenarios—where only a few examples of a target category are provided—is a critical challenge in computer vision. Traditional methods often struggle to balance counting accuracy with precise object localization, especially in dense scenes. This paper presents CoDi (Counting by Diffusion), the first latent diffusion-based framework for low-shot counting. By treating counting as an iterative generative refinement process, CoDi generates sharp, high-quality density maps. Our model utilizes a novel Exemplar-Based Conditioning (EC) mechanism to dynamically adapt to object appearance and shape. Experimental results demonstrate that CoDi sets a new state-of-the-art, improving Mean Absolute Error (MAE) by up to 44% on challenging benchmarks.
Introduction
Estimating the number of objects in an image is vital for fields such as wildlife monitoring and medical diagnostics. Current methodologies typically fall into two categories: density-based regression and detection-based counting. While density-based methods excel at global counting, they often produce blurry heatmaps that hinder precise localization. Conversely, detection-based methods provide clear locations but frequently fail in highly congested scenes where objects are small and overlapping. Furthermore, many state-of-the-art counters are limited by a fixed number of object queries, restricting their utility in scenes with thousands of items.
CoDi addresses these limitations by leveraging the iterative refinement capabilities of diffusion models to produce "crisp" localization maps even in the densest regions, effectively bridging the gap between counting and localization.
Methods
CoDi employs a Latent Diffusion Model (LDM) to transform initial Gaussian noise into a precise map of object locations through a series of denoising steps. This process is conditioned on user-provided exemplars to specify the target object class.
Exemplar-Based Conditioning (EC)
A core innovation is the EC module, which extracts both appearance and shape prototypes from the provided bounding boxes. Unlike static conditioning used in standard diffusion models, CoDi’s EC module is dynamic; it adjusts prototypes at every denoising step and across different network layers. This ensures that the guidance remains synchronized with the evolving features in the latent space.
Efficiency and Adaptability
By operating in a compressed latent space rather than on raw pixels, CoDi maintains high computational efficiency, processing images in approximately 0.6 seconds. For cases where no exemplars are available, the model supports a "reference-less" mode using trainable "queries" to automatically identify and count the most prominent objects in a scene.
Results
The performance of CoDi was evaluated on the FSC147 and Multi-Class Agnostic Counting (MCAC) benchmarks.
Quantitative Performance
- FSC147: CoDi achieved a 15% improvement in Mean Absolute Error (MAE) compared to previous state-of-the-art few-shot counters.
- MCAC: On this complex multi-class benchmark, CoDi reduced MAE by 44%, demonstrating superior robustness in distinguishing between different object categories within a single image.
- Localization: Qualitatively, the model produces distinct peaks for each object, facilitating accurate center-point localization through simple non-maxima suppression.
Conclusion and Future Work
CoDi represents a significant advancement in low-shot counting by successfully applying latent diffusion to the task. Its ability to generate high-fidelity localization maps while maintaining state-of-the-art counting accuracy solves a long-standing trade-off in the field. Future research will focus on improving performance for objects with extreme aspect ratios and extending the model to predict full bounding boxes, potentially evolving CoDi into a general-purpose low-shot object detector.
Summary updated