Abstract
Class-agnostic object counting aims to count object instances of an arbitrary class at test time. Current methods for this challenging problem require human-annotated exemplars as inputs, which are often unavailable for novel categories, especially for autonomous systems. Thus, we propose zero-shot object counting (ZSC), a new setting where only the class name is available during test time. Such a counting system does not require human annotators in the loop and can operate automatically. Starting from a class name, we propose a method that can accurately identify the optimal patches which can then be used as counting exemplars. Specifically, we first construct a class prototype to select the patches that are likely to contain the objects of interest, namely class-relevant patches. Furthermore, we introduce a model that can quantitatively measure how suitable an arbitrary patch is as a counting exemplar. By applying this model to all the candidate patches, we can select the most suitable patches as exemplars for counting. Experimental results on a recent class-agnostic counting dataset, FSC-147, validate the effectiveness of our method. Code is available at https://github.com/cvlabstonybrook/zero-shot-counting.
Introduction
Object counting is a vital task in computer vision, used for everything from wildlife monitoring to crowd control. Traditionally, this required class-specific models (one model for cars, another for cells). Recently, class-agnostic (few-shot) counting emerged, where a user provides a few "exemplars" (bounding boxes) of an object, and the model finds the rest.
However, requiring a human to draw boxes at test time is a bottleneck for autonomous systems. While some "exemplar-free" methods exist, they are often "blind" to specific categories, counting the most frequent object in an image regardless of user intent. This research introduces Zero-Shot Object Counting (ZSC), a setting where the system specifies exactly what to count using just a class name, without any manual annotation.
Methods
The proposed ZSC framework utilizes a two-step pipeline to transform a text label into a precise count:
1. Class-Relevant Patch Selection
To bridge the gap between text and pixels, the system uses a Conditional Variational Autoencoder (CVAE). Given a class name (converted into a semantic vector via CLIP), the CVAE "hallucinates" visual features of that object in a pre-trained ImageNet feature space. These features are averaged to create a class prototype. The system then samples random patches from the query image and retains those that most closely match this prototype.
2. Optimal Exemplar Selection (The Error Predictor)
Not every patch containing the object is a good counting guide; partial or obscured views can lead to inaccuracies. The authors introduced a novel Error Predictor network ($R$) that quantitatively measures how suitable a patch is as a counting exemplar. By applying this model to candidate patches, the system selects those with the lowest predicted error to serve as the final counting guides.
Key Insights and Ideas
A critical insight of this work is that "belonging to the class" is insufficient for a patch to be a high-quality exemplar. By training a model to specifically predict counting error, the authors created a filter for visual quality and representativeness.
As shown in the visualization above, the Error Predictor successfully identifies complete, centered object instances (left) while assigning higher error scores to partial or cluttered patches (right). This automated selection process allows ZSC to act as an automated search for the best few-shot exemplars, making it compatible with existing few-shot models like FamNet or BMNet.
Key Results
- State-of-the-Art Performance: On the FSC-147 dataset, the proposed ZSC method significantly outperformed previous exemplar-free leaders, reducing the Root Mean Squared Error (RMSE) from 98.73 to 88.63 on the validation set.
- Closing the Gap: The method performs remarkably close to few-shot models that utilize human-provided boxes. In some metrics, such as Normalized Relative Error, the automated patch selection actually outperformed manual annotation.
- Multi-Class Flexibility: Unlike previous automated counters, this method can distinguish between multiple categories in the same image (e.g., counting "grapes" vs. "oranges") simply by changing the input text.
Conclusion
Zero-Shot Object Counting represents a significant advancement toward fully autonomous visual perception. By combining semantic prototypes with a learned error-prediction mechanism, the system eliminates the need for human intervention while maintaining high accuracy across diverse object categories. Future work will explore end-to-end training of the selection and counting modules to further refine the synergy between finding exemplars and using them.
Summary updated