Introduction
Object counting is a fundamental task in computer vision with applications ranging from crowd monitoring to biological research. However, traditional methods are often "category-specific," requiring extensive labeled data for every new object type. This CVPR 2021 paper proposes a paradigm shift toward few-shot counting, where a model can count any object category at test time given just a few user-provided examples.
The Challenge of Category-Specific Counting
Most existing counting models are trained for a single class, such as people or cars. This approach faces two major hurdles:
- Data Scarcity: Collecting thousands of dot-annotated images for every novel category is unscalable.
- Limited Diversity: Existing datasets lack the variety needed to train a truly general-purpose counter.
The authors address this by asking: can a model learn to count a novel object category using only 1–3 example bounding boxes?
Methodology: FamNet
The proposed Few Shot Adaptation and Matching Network (FamNet) treats counting as a similarity matching task. Instead of classifying objects, it identifies regions in an image that correlate with the provided exemplars.
The architecture consists of:
- Feature Extraction & Correlation: A ResNet-50 backbone extracts multi-scale features. These are used to generate correlation maps that highlight similarities between the full image and the exemplars.
- Density Prediction: Rather than discrete detection, the model predicts a continuous density map. The total count is the integral of this map, which is more robust to overlaps and occlusions.
- Test-time Adaptation: A critical innovation where the model fine-tunes itself on the fly using the provided exemplars. It employs a Min-Count Loss (ensuring at least one object is counted in exemplar boxes) and a Perturbation Loss (ensuring density follows a clean Gaussian distribution).
The FSC-147 Dataset
To facilitate general-purpose counting, the authors introduced FSC-147 (Few-Shot Counting-147), a massive dataset designed for diversity and scale.
As shown in the comparison above, FSC-147 provides a much broader range of categories (147 vs. 1 in most benchmarks) and includes both dot and bounding box annotations. The categories span food, animals, vehicles, and household items, with object counts per image ranging from a few to over 300.
Key Results and Insights
- Superior Accuracy: FamNet achieved a Mean Absolute Error (MAE) of 22.08 on the FSC-147 test set, significantly outperforming few-shot detection baselines (MAE 32.53).
- Robust Generalization: The model demonstrated strong performance on the CARPK dataset even when trained on unrelated categories, proving its ability to adapt to specific domains with minimal input.
- Density vs. Detection: The study confirms that density estimation is more effective than detection for counting, especially in dense scenes where bounding boxes frequently overlap.
Conclusion
"Learning To Count Everything" moves the field toward class-agnostic visual counting. By combining similarity matching with test-time adaptation and a diverse new dataset, FamNet provides a scalable solution for counting virtually any object with minimal human intervention.
Source: Ranjan, V., et al. (2021). Learning To Count Everything. CVPR.
Summary updated