File size: 3,111 Bytes
383a563 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 | ---
license: mit
language:
- en
library_name: pytorch
pipeline_tag: zero-shot-object-detection
tags:
- CountGD++
- computer-vision
- counting
- grounding-dino
- model_hub_mixin
- multi-modal
- open-vocabulary
- pytorch_model_hub_mixin
---
# 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](https://arxiv.org/abs/2512.23351) · [Code](https://github.com/niki-amini-naieni/CountGDPlusPlus)

This repository holds both the **weights** (`model.safetensors`, `config.json`)
and the **inference code**, so nothing has to be downloaded from Google Drive.
## Usage
```bash
pip install torch torchvision "transformers<4.50" timm addict "yapf==0.40.1" termcolor \
scipy matplotlib opencv-python-headless pycocotools pyyaml huggingface_hub safetensors
```
```python
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

## Citation
```bibtex
@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}
}
```
|