Represent, Compare, and Learn: A Similarity-Aware Framework for Class-Agnostic Counting

Min Shi, Hao Lu, Chen Feng, Chengxin Liu, Zhiguo Cao

Introduction

Object counting is a fundamental computer vision task typically approached through class-specific models trained for narrow domains, such as crowd or vehicle counting. However, Class-Agnostic Counting (CAC) presents a more significant challenge: given a query image and a few "exemplar" bounding boxes of a novel object, the model must count all instances of that object regardless of its category.

Traditional CAC methods rely on an "extract-and-match" pipeline, where features from the exemplar and query image are compared using a fixed similarity metric, such as a simple inner product. The authors of this paper identify a critical bottleneck in this approach: fixed metrics often produce noisy matching maps, leading to poor generalization and inaccurate counts. As illustrated in Figure 1, previous state-of-the-art methods like FamNet frequently struggle with background noise and weak activations on target objects.

Visual comparison of similarity maps. BMNet+ produces much cleaner, higher-fidelity results than previous methods.

Methodology: A Similarity-Aware Framework

To address these limitations, the authors propose a framework that treats similarity matching as a learnable component. By jointly learning how to represent objects and how to compare them, the model becomes more robust to variations in scale, pose, and lighting. The research introduces two primary models:

  1. BMNet (Bilinear Matching Network): A baseline model that replaces the standard inner product with a learnable bilinear similarity metric, allowing the system to capture complex interactions between feature channels.
  2. BMNet+: An enhanced architecture that incorporates three sophisticated modules to refine the counting process:
  3. Self-Similarity Module: Utilizing self-attention, this module allows the model to aggregate information from other potential instances within the query image, building a more robust prototype of the target object.
  4. Dynamic Similarity Metric: This module adaptively weights feature channels based on the specific exemplar provided, focusing on the unique patterns (e.g., texture vs. shape) that define that particular object.
  5. Similarity Loss: A novel supervision signal that explicitly trains the model to maximize similarity for target objects and minimize it for the background, effectively framing matching as a metric learning problem.
The full pipeline of BMNet+. It includes a self-similarity module, a dynamic similarity metric, and dual losses for counting and similarity.

Experimental Evaluation

The models were evaluated on the FSC147 dataset, the gold standard for CAC, which contains over 6,000 images across 147 categories with no overlap between training and testing sets. To test cross-dataset generality, the models were also evaluated on the CARPK car-counting dataset without further fine-tuning.

Key Results

BMNet+ established a new state-of-the-art performance on the FSC147 benchmark:

  • Quantitative Accuracy: On the FSC147 test set, BMNet+ achieved a Mean Absolute Error (MAE) of 14.62, representing a 33% relative improvement over the previous best-performing model, FamNet+ (MAE 22.08).
  • Generalization: Without fine-tuning, BMNet+ significantly outperformed FamNet on the CARPK dataset (MAE 10.44 vs. 28.84), demonstrating superior zero-shot transfer capabilities.
  • Efficiency: Despite its architectural enhancements, BMNet+ remains computationally efficient, capable of running on a single consumer-grade GPU with less than 12GB of VRAM.

Conclusion and Future Work

The success of BMNet+ highlights that similarity in class-agnostic counting is not merely a mathematical operation but a feature that can be learned. By making the matching process dynamic and context-aware, the framework achieves unprecedented accuracy. Future research directions include exploring more advanced feature backbones beyond ResNet-50, investigating Transformer-based fusion techniques for similarity maps, and developing methods to better preserve spatial resolution and scale information during feature extraction.

Summary updated

BibTeX
@inproceedings{shi2022represent,
  author = {Min Shi and Hao Lu and Chen Feng and Chengxin Liu and Zhiguo Cao},
  title = {{Represent, Compare, and Learn: A Similarity-Aware Framework for Class-Agnostic Counting}},
  booktitle = {IEEE/CVF Conference on Computer Vision and Pattern Recognition},
  year = {2022},
}
Figure