CountGD++

CountGD++: Generalized Prompting for Open-World Counting (CVPR 2026)

A multi-modal open-world counting model. You say what to count with text, visual exemplars (boxes on example objects), or both. You can also say what not to count with negative text and negative exemplars. Exemplars can come from the image being counted or from a different image.

Paper · Code

teaser

This repository holds both the weights (model.safetensors, config.json) and the inference code, so nothing has to be downloaded from Google Drive.

Usage

pip install torch torchvision "transformers<4.50" timm addict "yapf==0.40.1" termcolor \
    scipy matplotlib opencv-python-headless pycocotools pyyaml huggingface_hub safetensors
import sys
from huggingface_hub import snapshot_download

repo = snapshot_download("nikigoli/CountGDPlusPlus")   # code + weights
sys.path.insert(0, repo)
from countgdpp import CountGDPlusPlus, count

model = CountGDPlusPlus.from_pretrained("nikigoli/CountGDPlusPlus").to("cuda").eval()

# Text only
print(count(model, f"{repo}/img/336.jpg", "strawberry")["count"])

# Positive text + negative text
print(count(model, f"{repo}/img/336.jpg", "strawberry", negative_texts=["blueberry"])["count"])

# Text + visual exemplars drawn on another image, with a negative exemplar
result = count(
    model, f"{repo}/img/336.jpg", "strawberry",
    exemplar_boxes=[[x1, y1, x2, y2]],                    # pixels, on exemplar_image
    exemplar_image=f"{repo}/img/synthetic_strawberry.jpg",
    negative_texts=["blueberry"],
    negative_exemplar_boxes=[[[x1, y1, x2, y2]]],          # one list per negative text
    negative_exemplar_images=[f"{repo}/img/synthetic_blueberry.jpg"],
)
print(result["count"], result["boxes"])   # boxes: normalized (cx, cy, w, h)

example.py is a runnable version that also saves a picture of the detections.

Notes:

  • The text encoder (bert-base-uncased) is fetched from the Hugging Face Hub by transformers the first time the model loads.
  • The compiled multi-scale deformable attention kernels are optional. Without them the model uses an equivalent pure-PyTorch implementation on CPU or GPU. To compile the kernels, see the GitHub repository.
  • Pseudo-exemplars and adaptive cropping used for some benchmark results are not part of count(). See the test scripts in the GitHub repository.

Architecture

architecture

Citation

@InProceedings{AminiNaieni26b,
  title={CountGD++: Generalized Prompting for Open-World Counting},
  author={Amini-Naieni, N. and Zisserman, A.},
  booktitle = {Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition (CVPR)},
  year={2026}
}
Downloads last month
-
Safetensors
Model size
0.2B params
Tensor type
I64
·
F32
·
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Paper for nikigoli/CountGDPlusPlus