Point, Segment and Count: A Generalized Framework for Object Counting

Zhizhong Huang, Mingliang Dai, Yi Zhang, Junping Zhang, Hongming Shan

Abstract

Object counting has traditionally relied on density-based methods that lack interpretability or detection-based methods that struggle with dense scenes. We present PseCo (Point, Segment, and Count), a generalized framework that leverages foundation models like SAM and CLIP for class-agnostic counting. By utilizing a lightweight point decoder for smart prompting and hierarchical knowledge distillation for classification, PseCo achieves state-of-the-art performance on benchmarks like FSC-147 while providing transparent, detection-based visual feedback.

Introduction

Object counting has historically been a specialized field, with models typically trained for specific categories like crowds or vehicles. Class-agnostic counting aims to overcome this by allowing a single model to count arbitrary objects using either a class name (zero-shot) or a few example images (few-shot).

Existing approaches generally fall into two categories: density-based methods and detection-based methods. While density maps are accurate, they function as "black boxes" without individual object localization. Conversely, detection-based methods are intuitive but often fail in highly crowded scenes and require expensive bounding box annotations. PseCo bridges this gap by adapting foundation models—the Segment Anything Model (SAM) and CLIP—into an efficient, interpretable "detect-and-count" pipeline.

The PseCo Framework

PseCo introduces a three-step pipeline designed to maximize the efficiency and precision of foundation models for the counting task.

The PseCo framework architecture showing the Point, Segment, and Count modules.
  1. Point (Class-Agnostic Localization): Naive application of SAM often involves a slow, uniform grid of points. PseCo instead employs a lightweight Point Decoder to predict a heatmap of potential object centers. These predicted points serve as high-quality prompts for SAM, significantly reducing computational overhead while ensuring small objects in dense clusters are detected.
  2. Segment (SAM): Using the predicted points as prompts, SAM generates hierarchical mask proposals representing different levels of object granularity (e.g., whole, part, or subpart).
  3. Count (CLIP + Hierarchical Knowledge Distillation): To classify these masks, PseCo uses CLIP embeddings derived from text or image queries. A critical challenge is the "part-whole" ambiguity, where SAM may segment a wheel, a door, and the entire car for a single point. PseCo utilizes Hierarchical Knowledge Distillation (HKD) to help the classifier select the correct hierarchical level, preventing double-counting and ensuring consistency.

Experimental Evaluation

The framework was evaluated on several rigorous benchmarks, including FSC-147 (the standard for class-agnostic counting), COCO, LVIS, and FSCD-LVIS.

PseCo achieved state-of-the-art results on FSC-147, recording a Mean Average Error (MAE) of 13.05 in few-shot settings and 16.58 in zero-shot settings. Notably, in few-shot detection tasks, PseCo nearly doubled the Average Precision of previous leading models like C-DETR. Even in zero-shot scenarios using only text prompts (e.g., "strawberries"), the model outperformed specialized zero-shot counters.

Qualitative Analysis and Discussion

A primary advantage of PseCo is its interpretability. By providing bounding boxes for every counted object, users can visually verify results—a significant improvement over traditional density-map methods.

Qualitative comparison of counting results for hot air balloons, apples, and sheep.

As shown in the qualitative comparisons, PseCo's smart prompting strategy is more efficient than brute-force methods. While naive SAM usage might rely on over 1,000 grid points, PseCo's point decoder identifies objects using an average of only ~380 points, enhancing both speed and accuracy for small objects.

Conclusion

PseCo demonstrates that foundation models can be effectively adapted for generalized object counting through a structured detection-based approach. While challenges remain regarding heavy occlusion and prompt sensitivity, the framework's ability to provide accurate, interpretable counts across diverse categories marks a significant advancement in the field. Future work may involve integrating multi-modal Large Language Models to further refine reasoning for complex counting queries.

Summary updated

BibTeX
@inproceedings{huang2023point,
  author = {Zhizhong Huang and Mingliang Dai and Yi Zhang and Junping Zhang and Hongming Shan},
  title = {{Point, Segment and Count: A Generalized Framework for Object Counting}},
  booktitle = {IEEE/CVF Conference on Computer Vision and Pattern Recognition},
  year = {2023},
}
Figure