CLIP-Count: Towards Text-Guided Zero-Shot Object Counting

Ruixiang Jiang, Lingbo Liu, Changwen Chen

Introduction

Object counting is a fundamental computer vision task with applications ranging from ecological monitoring to urban planning. Traditionally, models have been categorized into class-specific systems—trained for a single category like pedestrians—or class-agnostic systems capable of counting arbitrary objects. Within the class-agnostic domain, the current state-of-the-art relies on "few-shot" counting, where users provide manual bounding boxes as exemplars. However, this requirement creates a significant operational bottleneck.

CLIP-Count introduces a paradigm shift by enabling the first end-to-end pipeline for text-guided, zero-shot object counting. By leveraging the pre-trained Contrastive Language-Image Pre-training (CLIP) model, CLIP-Count allows users to specify targets via natural language prompts (e.g., "car" or "apple") without any manual annotation or example boxes at inference time.

Addressing the Limitations of Current Paradigms

Existing class-agnostic methods typically follow a "counting-by-similarity" approach, comparing user-provided exemplars to the rest of the image. While effective, the need for manual input limits scalability. Conversely, "reference-less" methods attempt to count without exemplars but often fail in complex scenes containing multiple object types; they lack a mechanism to distinguish the target category from other salient objects in the background.

CLIP-Count bridges this gap. It provides the flexibility of class-agnostic counting with the ease of a natural language interface, ensuring the model focuses only on the objects described by the user prompt.

Methodology

The CLIP-Count architecture adapts the CLIP Vision-Language Model (VLM) for the dense prediction task of density map estimation through three primary technical innovations:

1. Visual Prompt Tuning (VPT)

To maintain the general knowledge captured by CLIP while adapting it for counting, the authors employ Visual Prompt Tuning. Instead of fine-tuning the entire massive image encoder—which is computationally expensive and risks "forgetting" general features—the backbone remains frozen. A small set of learnable "visual prompts" is added to each layer, allowing for parameter-efficient transfer learning utilizing only approximately 17.3M trainable parameters.

2. Patch-Text Contrastive Loss

Standard CLIP is optimized for global image-text alignment. Counting, however, requires local precision. CLIP-Count introduces a novel Patch-Text Contrastive Loss that aligns specific image patches with the text embedding. This "dense alignment" ensures the model can distinguish between patches containing the target object and those containing background or irrelevant items, pulling positive patches closer to the text embedding while pushing negatives away.

3. Hierarchical Patch-Text Interaction

Objects in the wild vary significantly in scale. To handle this, the authors designed a module featuring Multi-Head Self-Attention (MHSA) and Multi-Head Cross-Attention (MHCA). This structure propagates textual information across multiple image resolutions, enabling the model to accurately detect both small-scale and large-scale objects within the same framework.

Experimental Evaluation

The model was rigorously tested across several benchmark datasets, including FSC-147 (the standard for class-agnostic counting), CARPK (overhead parking lots), and ShanghaiTech (crowd counting).

Performance Metrics

On the FSC-147 dataset, CLIP-Count established a new state-of-the-art for zero-shot counting:

  • CLIP-Count MAE: 18.79
  • Previous Zero-Shot SOTA MAE: 26.93

Remarkably, CLIP-Count’s zero-shot performance is competitive with several established few-shot methods, despite the latter having the advantage of manual visual exemplars.

Generalization and Robustness

In cross-dataset evaluations on CARPK, CLIP-Count demonstrated superior generalization. It achieved a Mean Absolute Error (MAE) of 11.96, significantly outperforming the leading reference-less method (RCC), which recorded an MAE of 21.38. This suggests that the model has learned a robust semantic understanding of the relationship between text and visual objects rather than simply memorizing training distributions.

Limitations and Future Outlook

Despite its success, CLIP-Count faces challenges common to vision-language models:

  • Semantic Ambiguity: The model may struggle to distinguish between a physical object and a representation of that object (e.g., counting a drawing of an apple on a sign when the user wants to count real fruit).
  • Self-Repeating Structures: Objects with complex, repetitive geometries (like the two lenses of a pair of sunglasses) can occasionally trigger double-counting if the model perceives the parts as individual targets.

Future research will likely focus on incorporating more granular text descriptions to resolve these ambiguities and further refining the dense alignment between text and visual features.

Conclusion

CLIP-Count represents a significant step forward in making object counting more accessible. By repurposing CLIP for dense prediction through visual prompt tuning and patch-level contrastive learning, it removes the need for tedious manual annotations, providing a flexible and intuitive interface for zero-shot counting tasks.

Summary updated

BibTeX
@inproceedings{jiang2023clip,
  author = {Ruixiang Jiang and Lingbo Liu and Changwen Chen},
  title = {{CLIP-Count: Towards Text-Guided Zero-Shot Object Counting}},
  booktitle = {ACM Multimedia},
  year = {2023},
  doi = {10.1145/3581783.3611789},
}
Figure