T-Rex: Counting by Visual Prompting

Qing Jiang, Feng Li, Tianhe Ren, Shilong Liu, Zhaoyang Zeng, Kent Yu, Lei ZhangarXiv 2023 · DOI

Introduction

Object counting—estimating the number of specific items like cells in a petri dish, cars in a lot, or seedlings in a field—is a critical task across numerous industries. However, traditional solutions face significant hurdles. Density map regression models are difficult for humans to verify or correct. Closed-set detectors like YOLO are limited to pre-defined categories. Furthermore, text-prompted open-vocabulary models often struggle to describe complex industrial or biological objects precisely; for instance, describing a specific type of industrial screw or a particular biological microorganism using only words is often impossible.

T-Rex supports intra-image and cross-image counting across diverse domains using visual prompts like boxes and points.

T-Rex shifts the paradigm from text-based instructions to visual prompting. By simply drawing a box or clicking on an exemplar object, users can trigger the model to detect and count all similar instances across images. This approach achieves state-of-the-art results on major benchmarks while offering an intuitive, "human-in-the-loop" refinement process that bridges the gap between automated detection and human expertise.

Methods

T-Rex is built on a detection-based architecture designed for open-set tasks. Its workflow consists of three main components: an Image Encoder for extracting high-level visual features, a Prompt Encoder for processing user-defined visual templates (boxes or points), and a Box Decoder that correlates these templates with target image features to predict bounding boxes and confidence scores.

The T-Rex architecture features a single-round forward pass for feature extraction and a multi-round interaction loop for human feedback.

Key Innovations

  • Visual Prompting: Instead of ambiguous text descriptions, visual prompts capture fine-grained details like texture, shape, and color directly. This allows the model to focus on the visual language of the object itself.
  • Interactive Refinement: T-Rex supports real-time feedback. If the model misses an object or detects a distractor, users can add "positive" or "negative" prompts. The model then updates its predictions in a fast, iterative loop.
  • Efficiency through Decoupling: Because the Image Encoder only needs to run once per image, subsequent rounds of interactive prompting—using only the Prompt Encoder and Box Decoder—are extremely fast and resource-efficient.
  • Cross-Image Counting: T-Rex can take a prompt from one image and use it to count objects in another, making it highly efficient for batch processing across large datasets.

Datasets and Benchmarks

The model was evaluated on established benchmarks like FSC147 (147 categories) and FSCD-LVIS. Additionally, the authors introduced the Count Anything-44 (CA-44) benchmark, featuring 44 datasets across 8 diverse domains: Agriculture, Animal, Aerial, Biology, Human, Industry, Objects, and OCR. CA-44 contains over 30,000 images and 1.17 million instances, specifically curated to represent dense, real-world counting scenarios that challenge existing models.

Key Results and Insights

T-Rex sets a new performance standard across the board:

  • State-of-the-Art Performance: On the FSC147 test set, T-Rex achieved a Mean Average Error (MAE) of 10.59 in one-shot settings and 8.72 in three-shot settings, significantly outperforming previous models like CountTR and LOCA.
  • Superiority over MLLMs: In head-to-head comparisons on CA-44, T-Rex consistently outperformed GPT-4V in both zero-shot and one-shot scenarios, particularly in dense scenes where general-purpose multi-modal models tend to lose track or hallucinate.
  • Interpretability and Trust: By treating counting as a detection task (outputting boxes) rather than regression (outputting a density map), T-Rex provides verifiable visual evidence. Users can see exactly what the model is counting, which allows for precise error correction.

Limitations and Future Work

Despite its strengths, T-Rex can struggle in extremely sparse scenes with a single prompt, occasionally failing to distinguish objects from backgrounds or misidentifying dense clusters as single units. In cross-image mode, it may over-fit to the specific appearance of the reference object, leading to errors if target objects have slight variations. Future work will focus on improving robustness in "dense multi-object" scenes where multiple types of similar objects are present, potentially by further refining the negative prompting logic.

Summary updated

BibTeX
@misc{jiang2023t,
  author = {Qing Jiang and Feng Li and Tianhe Ren and Shilong Liu and Zhaoyang Zeng and Kent Yu and Lei Zhang},
  title = {{T-Rex: Counting by Visual Prompting}},
  year = {2023},
  eprint = {2311.13596},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2311.13596},
}
Figure