Introduction
Class-agnostic counting (CAC) is a versatile computer vision task where a model is expected to count instances of any object category given only a few visual examples (exemplars). While existing models perform well on single-class images, they frequently fail in multi-class environments—a phenomenon the authors term "greedy counting." When presented with an exemplar of one object (e.g., an apple) in a scene containing multiple types (e.g., apples and oranges), current state-of-the-art models often count all objects indiscriminately. This occurs because these models are typically trained on single-class datasets, leading them to prioritize general "object-ness" over class-specific discriminative features.
The Segment-and-Count Framework
To address this, the authors propose a two-stage "localize first, count second" strategy. The core idea is to use a segmentation model as a denoising filter that removes irrelevant object classes before the counting process begins.
1. Pseudo-Labeling for Segmentation
A significant challenge in training segmentation models for counting is the lack of pixel-level annotations; most datasets only provide point annotations (dots). The authors overcome this by generating pseudo-masks through unsupervised clustering. They apply K-means to feature embeddings to group similar pixels. To determine the optimal number of clusters ($K$), they utilize a pre-trained "base" counter. By testing masks generated with different $K$ values, the system selects the mask that minimizes the L2 distance between the predicted density map and the ground-truth dot annotations.
2. Training and Inference
Once pseudo-masks are generated, a dedicated exemplar-based segmentation model is trained. This model learns to produce a binary mask highlighting only objects that match the provided exemplars. During inference, this mask is applied to the similarity map generated by the feature extractor, effectively "blacking out" non-target regions before they reach the density-based counter.
Experimental Setup
The framework was evaluated on three primary benchmarks:
- FSC-147: The standard benchmark for class-agnostic counting (6,135 images across 147 categories).
- Synthetic Multi-Class Dataset: A new dataset created by concatenating images of different classes from FSC-147 to simulate complex environments.
- Real-World Multi-Class Test Set: A newly curated set of 450 real-world images containing diverse object categories in single frames (e.g., mixed fruits or candies).
Results and Discussion
The proposed method demonstrates superior performance, particularly in complex multi-class scenarios where traditional models struggle.
On the Synthetic Multi-Class dataset, the model achieved a Mean Average Error (MAE) of 11.13, a massive improvement over SAFECount (26.44) and BMNet+ (39.78). Similarly, on the Real-World Multi-Class set, the model's MAE of 6.97 nearly halved the error of FamNet (13.54).
The Invariance-Discriminative Trade-off
The success of this approach lies in balancing invariance and discriminative power. While CAC models must be invariant to intra-class variations (e.g., different shapes of the same fruit), they must remain discriminative enough to exclude other classes. By treating segmentation as a preprocessing step, the authors decouple these requirements, allowing the counter to focus on density estimation while the segmentation module handles class discrimination.
Conclusion
This research introduces an elegant solution to the "greedy counting" problem by leveraging counting error as a supervisory signal for segmentation. By filtering out irrelevant background and non-target objects, the "segment-and-count" pipeline significantly enhances the robustness of class-agnostic counting in real-world, multi-class environments. Future work may involve end-to-end optimization to further refine the coarse pseudo-masks generated by the current clustering approach.
Summary updated