CountGD: Multi-Modal Open-World Counting
- Publication
- NeurIPS 2024Conference
- First submitted to arXiv
- arXiv:2407.04619
Cite this paper · BibTeX
The citation identifies the linked source version. It cites the original paper and its authors.
@misc{retailproductcountgd2024,
title = {{CountGD: Multi-Modal Open-World Counting}},
author = {Niki Amini-Naieni and Tengda Han and Andrew Zisserman},
year = {2024},
eprint = {2407.04619},
archivePrefix = {arXiv},
url = {https://arxiv.org/abs/2407.04619}
}
When you ask a model to count something for you, there are two ways to tell it what to count.
One is to show it: box a few examples on the image and say "count these". The FamNet line of few-shot counting works this way. It counts accurately, but somebody has to draw the boxes every time.
The other is to tell it: type a word, "count the apples". That's more convenient, but "apple" covers red ones, green ones, slices and apple pie, and one word can carry only so much information, so these methods have always been less accurate than the ones that use box exemplars.
This paper comes from the VGG group at the University of Oxford, with Andrew Zisserman among the authors. They built CountGD, a counting model that takes both kinds of input: text only, exemplars only, or the two together.
Problem Definition

The authors see two reasons why exemplars are more accurate than text. First, describing an object may take many words, while one box says it all. Second, exemplars come from the same image, so they carry that image's viewpoint and lighting and sit closer to the things being counted than any text description.
But with exemplars alone, the model loses flexibility. Can the two kinds of prompt be used together? And when they are, can the text do something exemplars can't? In (d) above, for example, an exemplar boxes one object, and adding "left" makes the model count only the one on the left.
Solution

CountGD is built on GroundingDINO. GroundingDINO is an open-vocabulary detector: give it a piece of text and it boxes everything in the image that fits the description. Its image and text encoders were pretrained together on large amounts of detection and phrase-grounding data. The authors chose it over CLIP because its features are finer-grained and map onto regions of the image.
Turning Exemplars into Text
The most crucial step is treating exemplars as text.
The image first goes through the Swin-B encoder, which produces feature maps at three scales. The exemplar boxes are cut out of these feature maps with RoIAlign. The three feature maps are first upsampled to the same resolution, concatenated and squeezed to 256 channels with a convolution, and then features are taken at the exemplar box coordinates. Each exemplar becomes a 256-dimensional vector, the same length as a text token.
These exemplar tokens are then appended right after the text tokens and sent into the feature enhancer. All the attention GroundingDINO originally computed between text and image is now computed between "text plus exemplars" and the image, and self-attention among text tokens becomes self-attention among text and exemplars. As a result, the word "blueberry" and those few blueberry exemplars fuse from the very start into a fuller description of what to count.
The number of text tokens was variable to begin with, so once exemplars become tokens, the number of exemplars is variable too. Zero, one or three all work.
From Detection to Counting
After fusion, the 900 image tokens most similar to the prompt are picked from all the image tokens as queries for the decoder. The decoder has 6 layers, each of which lets the queries look at both the image and the prompt. Finally, every query computes a similarity with every prompt token, followed by a sigmoid:
Each query takes its highest score over all the prompt tokens. Any query above the threshold counts as one object, and adding them all up gives the answer.
So CountGD is a detection-based counter. It doesn't produce a density map; it actually finds where each object is and then counts how many there are.
During training, the image and text encoders are both frozen, and only the exemplar projection layer, the feature enhancer and the decoder are trained. The loss is the L1 distance between predicted center points and the ground truth plus a focal loss on the similarities, with the Hungarian algorithm matching queries to annotated objects. The only training data is FSC-147, and training runs for 30 epochs on a single A6000.
Two Inference-Time Fixes
Detection-based counting has two built-in problems, and the authors add a fix for each at inference time.
The first is the cap of 900. There are only 900 queries, so with more than 900 objects the count can't be completed. When the number of detections hits 900, the authors cut the image into several overlapping tiles, count each one separately and add up the results. The tile size is 4 times the average exemplar width and height, with an overlap of 1.25 times, so that every object appears whole in at least one tile.
The second is self-similarity. The two wings of a butterfly or the two lenses of a pair of sunglasses look alike, so the model easily counts one object as two. The authors feed the exemplar boxes to SAM to get masks; if more than one object is detected inside an exemplar's mask, the total is divided by that factor.
Discussion
FSC-147
| Method | Prompt | Val MAE | Test MAE | Test RMSE |
|---|---|---|---|---|
| CounTX | Text | 17.10 | 15.88 | 106.29 |
| CountGD | Text | 12.14 | 14.76 | 120.42 |
| CounTR | Exemplars | 13.13 | 11.95 | 91.23 |
| LOCA | Exemplars | 10.24 | 10.79 | 56.97 |
| DAVE | Exemplars | 8.91 | 8.66 | 32.36 |
| CountGD | Text + exemplars | 7.10 | 6.75 | 43.65 |
| CountGD, labels corrected on two images | Text + exemplars | 7.10 | 5.74 | 24.09 |
Source: Table 1 of the paper, excerpt. DAVE is concurrent work.
With text and exemplars together, CountGD has the lowest MAE of all the methods. With text only, it's roughly on par with the other text-based methods.
The last two rows deserve a closer look, though. The authors made two corrections to the FSC-147 test set. One image (7171.jpg) had wrong exemplars, so it now gets text only. Another (7611.jpg) had the text "lego", but what should be counted is actually the studs on the Lego bricks, so it became "yellow lego stud". After the corrections, test RMSE drops from 43.65 to 24.09.
The ablation in the appendix breaks this change down further:
| Inference setting | Test MAE | Test RMSE |
|---|---|---|
| No fixes at all | 10.92 | 99.58 |
| + SAM self-similarity fix | 9.62 | 98.90 |
| + Adaptive cropping | 6.75 | 43.65 |
| + Correct 7171.jpg exemplars | 5.70 | 24.04 |
| + Correct 7611.jpg text | 5.74 | 24.09 |
Source: Table 4 of the paper (appendix).
RMSE is very sensitive to extreme values. Correcting the exemplars of a single image cuts RMSE by nearly 20, and adaptive cropping takes it from 99 down to 44, because a few test images contain more than 900 objects.
So if you look only at the version without corrected labels, CountGD's test RMSE is 43.65, actually higher than the 32.36 of the concurrent DAVE, while its MAE is the lowest throughout. Correcting labels is fine in itself, and the authors list both versions; just keep the two apart when reading the table.
On Other Datasets
CARPK is an aerial parking-lot dataset for counting cars. CountGD, trained only on FSC-147 and never shown CARPK, gets an MAE of 3.83 from the word "car" alone, and 3.68 with two exemplar boxes added. CounTR and SAFECount, fine-tuned specifically on CARPK, get 5.75 and 5.33.
Each CountBench image has only 2 to 10 objects, whereas every FSC-147 training image has at least 7. With text only, CountGD's MAE is 0.86, against 6.64 for CounTX. GroundingDINO's pretraining pays off here, since it was already good at finding a handful of specific objects.
Text and Exemplars Fill Each Other's Gaps
The authors also froze the feature enhancer and fine-tuned a separate version to observe how text and exemplars interact.

The exemplar sets the shape, and the text can add a condition on color or position. Box a car and say "white", and only white cars are counted; box a pair of headphones and say "top row", and only the top row is counted. Neither exemplars alone nor text alone can do that. The authors say this is a preliminary qualitative observation, with no quantitative evaluation.
Reproduction
The code and the pretrained models are both public, and the authors answer questions actively in the issues. With the official pretrained model, you get the same numbers as the paper.
Retraining it yourself is another story. In October 2024, someone retrained the model and, with all the inference fixes turned on, got a test MAE above 7 and an RMSE above 80, well short of the paper's 5.74 and 24.09 (issue #16). In January 2026, someone retrained it by following the tutorial and got a test MAE of 8.01 and an RMSE of 82.63 (issue #60). The authors explain that CountGD is built on the Open-GroundingDINO code, which has nondeterminism beyond the random seed, so training can't be reproduced exactly; and RMSE is especially sensitive to the few images with more than 900 objects, so the best cropping threshold may shift with every retraining.
Conclusion
CountGD unifies the two kinds of prompt, text and exemplars, in a simple way. Exemplars are cut out of the image features and treated as extra text tokens, and the rest of GroundingDINO's pipeline runs as usual. With both prompts together, it has the lowest MAE on FSC-147; without training on the target dataset, it also beats fine-tuned methods on CARPK, and on CountBench it leads CounTX, which also uses text only, by a wide margin.
When reading the numbers, watch for two things. First, RMSE is very sensitive to a few extreme images. The paper's most impressive RMSE, 24.09, comes all the way down from 99.58 without fixes, most of the drop from cropping at inference time and the rest mainly from correcting the labels of one image. Second, if you retrain it yourself, your numbers may fall well short of the paper's.
On a shelf, CountGD suggests a very convenient way of working. Box one can of a drink, type "can" or "top shelf", and you might be able to count just one product on just one shelf level. The paper's interaction experiments are only a qualitative demonstration on a few images, though, so the real effect has to be tested on your own shelves. A single shelf photo often holds a hundred or more of the same product, and that's where the 900 cap and adaptive cropping come into play.