Abstract
Object counting is a fundamental computer vision task with applications ranging from industrial inspection to wildlife monitoring. While recent class-agnostic models can count arbitrary objects given visual exemplars, they still require human intervention at test time. This paper introduces Zero-Shot Object Counting (ZSC), a novel task where the target category is specified via natural language. We propose a framework that utilizes Stable Diffusion to generate image-specific visual prototypes and a novel Error Predictor to automatically select optimal exemplars from the query image. Our method achieves state-of-the-art performance on the FSC-147 benchmark, significantly reducing the Mean Average Error (MAE) compared to existing exemplar-free baselines.
Introduction
The evolution of object counting has moved from class-specific models (e.g., counting only cars) to class-agnostic models that can count any object given a few bounding box examples (exemplars). However, the requirement for human-provided exemplars limits the autonomy of these systems. Previous attempts at "exemplar-free" counting often defaulted to counting the most frequent object in a scene, lacking the specificity required for many real-world tasks. Zero-Shot Object Counting (ZSC) addresses this by allowing users to define the target object using natural language prompts (e.g., "grapes"), enabling a fully automated and flexible counting pipeline.
Methodology
The proposed ZSC framework bridges the gap between linguistic descriptions and numerical counts through a two-stage process: localizing class-relevant patches and selecting optimal exemplars.
1. Localizing Class-Relevant Patches
To translate a text label into visual information, the system generates a "visual prototype." While generic prototypes can be created using VAEs, the authors found that image-specific prototypes are more effective. By using Stable Diffusion (SD) to generate synthetic images of the target class, the model can select synthetic patches that match the specific appearance (color, shape, variety) of the objects in the query image. This handles intra-class variation, ensuring that if the prompt is "apple," the model selects red apple prototypes for an image containing red apples.
2. Selecting Optimal Exemplars via Error Prediction
Not all patches containing the target object are equally useful for counting; occlusions or poor framing can lead to inaccuracies. The framework introduces an Error Predictor (R), a secondary network that evaluates candidate patches. It analyzes the feature maps produced by a pre-trained counter and predicts the likely counting error associated with each patch. The patches with the lowest predicted error are selected as the final exemplars.
These selected exemplars are then processed by a base counting model (such as BMNet+ or FamNet) to generate a density map and the final object count.
Experiments and Results
The model was evaluated primarily on the FSC-147 dataset, a benchmark for class-agnostic counting containing over 6,000 images across 147 categories.
Quantitative Results
The SD-based zero-shot method achieved a Mean Average Error (MAE) of 21.53 on the FSC-147 test set. This represents a significant improvement over baseline exemplar-free methods like RepRPN (MAE 27.45) and simple RPN-based selection (MAE 29.25). Furthermore, the selection method proved to be "plug-and-play," improving the performance of various base counters. For instance, it reduced the MAE of BMNet+ from 34.52 (with random selection) to 23.14.
Qualitative Analysis
The model demonstrates robust performance across diverse categories, including food items, animals, and consumer goods. It successfully distinguishes target objects from background clutter and handles multi-class scenarios where different categories must be counted independently within the same image.
Discussion and Conclusion
A key insight of this work is that the "goodness" of an exemplar is a predictable quality. By learning to identify feature map patterns associated with low counting error, the model can automate a task previously requiring human intuition. Additionally, the use of generative models like Stable Diffusion allows the system to "hallucinate" relevant visual context, adapting to the specific intra-class variations present in a query image.
While the model shows great promise, it faces challenges with semantic ambiguity (e.g., "kiwi" bird vs. fruit) and very generic prompts. Future work focusing on prompt engineering and more sophisticated linguistic-visual alignment could further enhance the precision and reliability of zero-shot counting systems.
Summary updated