Grounding DINO: Marrying DINO with Grounded Pre-Training for Open-Set Object Detection
- Publication
- ECCV 2024Conference
- First submitted to arXiv
- arXiv:2303.05499
Cite this paper · BibTeX
The citation identifies the linked source version. It cites the original paper and its authors.
@misc{objectdetectiongroundingdino2023,
title = {{Grounding DINO: Marrying DINO with Grounded Pre-Training for Open-Set Object Detection}},
author = {Shilong Liu and Zhaoyang Zeng and Tianhe Ren and Feng Li and Hao Zhang and Jie Yang and Qing Jiang and Chunyuan Li and Jianwei Yang and Hang Su and Jun Zhu and Lei Zhang},
year = {2023},
eprint = {2303.05499},
archivePrefix = {arXiv},
url = {https://arxiv.org/abs/2303.05499}
}
Take a detector trained on COCO and ask it to box the "Ferris wheel."
It can't. COCO has only 80 categories, and the Ferris wheel isn't on the list; the classifier in the model's last layer has just 80 outputs, so however hard it tries, it can only pick one of those 80 names.
To get a detector to understand arbitrary nouns, or even a whole phrase like "the lion on the left," you have to bring language in. By around 2022 there were already several ways to wire it in; GLIP recast detection as a problem of matching phrases to regions, and OV-DETR used CLIP vectors as DETR's queries.
The authors of this paper come from IDEA and Tsinghua University, and the first author, Shilong Liu, is also one of the authors behind DAB-DETR, DN-DETR and DINO, the line of DETR improvements. They had DINO, which had just set a new COCO record, and the title spells out their plan, to "marry" DINO with grounded pre-training.

The figure above shows the three scenarios this paper deals with. On the far left is traditional closed-set detection. The two middle columns are open-set detection, where the user can give new category names or a descriptive phrase; the latter is called referring expression comprehension (REC), and each phrase corresponds to exactly one object. On the far right is an application the authors show in passing, where Grounding DINO first finds the thing to change and Stable Diffusion then redraws it.
Defining the Problem
The authors start by taking apart the question of how to turn a closed-set detector into an open-set one.

A closed-set detector has roughly three stages, with the backbone extracting features, the neck strengthening them and the head outputting boxes. The most basic way to make it recognize new categories is to replace the final classifier with a similarity between region features and text features, so that whichever text is most similar wins. That is the contrastive loss in the figure.
The trouble is that if they are compared only at the last step, the image and text features grow up separately, and by the time they meet they are hard to align. So many methods fuse earlier, and the figure marks three places where this can happen:
- A: the neck. GLIP lets image and text features attend to each other here.
- B: query initialization. OV-DETR uses text vectors as the decoder's input queries.
- C: the head. The model keeps consulting the text while it decodes boxes.
The authors argue for fusing at all three. The more fusion there is, the more easily the two kinds of features align.
That sounds simple enough, so why did earlier methods fuse at only one or two of them?
The authors put it down to the structure of the detectors. Classic detectors like Faster R-CNN are made of specialized steps such as region proposals and RoI pooling, so language features have a hard time interacting with most of the blocks. The DETR family is different. From encoder to decoder it is layer after layer of attention plus feed-forward networks, the same shape as the Transformers that process language. With modules of the same shape on both sides, it is easy to have them attend to each other at whichever layer you like.
That is why DINO was chosen.
The other question is pre-training data. Many open-vocabulary detectors rely on CLIP for semantics, but CLIP was trained on whole images against whole sentences, and RegionCLIP had already pointed out that it is not ideal for matching regions to phrases. GLIP took a different route, stringing the category names of detection data into a sentence and training on it as phrase grounding together with grounding data and caption data. Grounding DINO follows this route but changes one detail, which we will get to later.
Solving the Problem

The figure has three parts; the left shows the whole picture, and the right zooms in on two new modules. We'll walk through the figure's example, with a photo of a cat and the text "cat . person . mouse ." as input.
First come the two backbones. The image goes through a Swin Transformer, which extracts multi-scale features; the text goes through BERT-base, and each token gets a vector. Both sides are projected to dimensions. The number of image tokens is usually over ten thousand (the feature maps of all scales flattened and counted together), while the number of text tokens is capped at 256.
The next three modules correspond exactly to the three fusion points A, B and C from earlier.
Feature Enhancer: A
The bottom-right block is one feature enhancer layer, and the model stacks six of them.
Each layer first lets each side sort itself out. The image features go through deformable self-attention (from Deformable DETR, where each position looks at only a few sampling points; otherwise having more than ten thousand tokens attend to each other would be too expensive), and the text features go through ordinary self-attention.
Then the two sides exchange information. First comes image-to-text cross-attention, where the image tokens act as queries and read the text tokens; then text-to-image cross-attention, where the text tokens act as queries and read the image back. Finally each side goes through its own FFN.
After six layers, the image features already carry "what this text is looking for," and the text features have seen the image. This part of the design draws on GLIP.
Language-Guided Query Selection: B
A DETR-style decoder needs a set of queries. DINO picks the 900 highest-scoring positions from the encoder output and uses them to initialize the queries.
Closed-set DINO picks them by classification score. But open-set detection has no fixed classifier, so what score should it use?
Grounding DINO's answer is to pick with the text. Multiplying the image features by the text features gives the similarity of every image token to every text token; each image token takes its highest score over all the text tokens, and the top are selected:
The pseudocode in the paper's appendix is only three lines:
# image_feat: (bs, num_img_tokens, ndim); text_feat: (bs, num_text_tokens, ndim)
logits = torch.einsum("bic,btc->bit", image_feat, text_feat) # (bs, num_img_tokens, num_text_tokens)
logits_per_img_feat = logits.max(-1)[0] # (bs, num_img_tokens)
topk_idx = torch.topk(logits_per_img_feat, num_query, dim=1)[1] # (bs, num_query)
In our example, the image positions most similar to "cat" rank at the top, so the queries start out near the cat. Change the text, and the selected positions change with it.
In the appendix, the authors draw these 900 selected boxes. The 900 boxes cover almost the whole image, yet on the same photo of a riverside city, switching among the three prompts building, river and ferris wheel gives different box distributions; the queries change with the prompt.
Once the positions are selected, how are the queries initialized? Grounding DINO keeps DINO's mixed query selection. Each query has a positional part and a content part. The positional part is an anchor box computed from the selected encoder output; the content part is a learnable vector and is not taken from the image features.
Cross-Modality Decoder: C
The top-right block is one decoder layer, again stacked six deep.
Compared with DINO's decoder, there is only one extra step. The queries first coordinate with one another through self-attention, then read the image through image cross-attention (deformable attention here), then go through an added text cross-attention that reads the text, and finally an FFN. Every layer has the queries look at the text once more; this is the fusion at position C.
The queries from the last layer are used to predict the boxes, and they also decide which phrase in the text each box corresponds to.
Sub-Sentence Text Features
Earlier we said that Grounding DINO changes one detail of GLIP. This is where.

To use detection data as grounding data, the category names first have to be strung into one sentence, such as "cat . baseball glove . person ." There are three choices for how to encode this string:
- (a) Sentence level. Each category name is encoded into its own vector. The categories don't interfere with one another, but each phrase is left with a single vector, and the details are lost.
- (b) Word level. The whole string goes into BERT together, and every word gets its own features. This is what GLIP does. The problem is that "cat" and "baseball glove" attend to each other, even though the order of these two category names is shuffled at random during training and there is no semantic relation between them at all.
- (c) Sub-sentence level. The whole string is still encoded together and per-word features are kept, but an attention mask lets only the words within the same category name see each other.
The official code uses periods, question marks and BERT's special tokens as separators; tokens attend to each other within a segment, and attention between segments is blocked. The position IDs of each segment also restart from 0. To the model, "baseball glove" looks the same wherever it falls in the list.
This is also why the prompts in the official examples are always written in the "cat . dog ." format.
Loss Function and Output
With no fixed categories, classification becomes a dot product between each query and each text token, giving a set of logits, and a focal loss is computed on each logit separately, following GLIP. For the boxes, the usual DETR-family L1 and GIoU losses apply, and Hungarian matching uses the same terms to compute its cost. Auxiliary losses are added to every decoder layer and to the encoder output.
At inference the model outputs 900 boxes, and each box has a score for each of the 256 token positions. The official code filters them with two thresholds. A box is kept if its highest score over all tokens exceeds box_threshold (0.35 in the examples); then the tokens scoring above text_threshold (0.25) are joined back into a phrase that serves as the box's label. For REC, only the single highest-scoring box is taken.
Training Setup
The model comes in two versions. Grounding DINO T uses Swin-T and is trained on 16 V100s; Grounding DINO L uses Swin-L and is trained on 64 A100s. Both use BERT-base as the text backbone; the T version has about 172M parameters and the L version about 341M.
The pre-training data falls into three groups:
- Detection data. COCO, Objects365 (O365) and OpenImages (OI). The category names are strung into text, and each training step randomly samples some of the categories to put into the prompt.
- Grounding data. GoldG (Flickr30k Entities and Visual Genome) and RefC (RefCOCO, RefCOCO+ and RefCOCOg), all in the versions prepared by MDETR.
- Caption data. Cap4M, 4 million captioned images with pseudo-label boxes generated by GLIP.
The T version uses O365v1 (about 600K images), and the L version the larger O365v2 (about 1.7M images).
Discussion
COCO Zero-Shot
The authors first compare zero-shot AP on COCO val2017 with GLIP and DINO:
- With O365 pre-training only, DINO (Swin-T) scores 46.2, Grounding DINO T 46.7 and GLIP-T 44.9.
- Adding the grounding data GoldG lifts Grounding DINO T to 48.1; adding Cap4M on top gives 48.4.
- Grounding DINO L, with O365, OI and GoldG, reaches 52.5. The comparison model, GLIP-L, scores 49.8, and its pre-training data even includes over twenty million more captioned images (Cap24M).
After fine-tuning on COCO, Grounding DINO L scores 62.6 on val against 62.5 for DINO (Swin-L), practically a tie; with images enlarged 1.5 times, it reaches 63.0 on test-dev.
LVIS: The Long-Tail Weakness
LVIS has over a thousand categories, many of them with only a few training images, which makes it a hard test of zero-shot ability. The results cut both ways:
- Grounding DINO T's overall AP is about the same as GLIP-T's (25.6 vs. 24.9, and 27.4 vs. 26.0 with Cap4M), but it does better than GLIP on common categories and worse on rare ones. With only O365 and GoldG, the rare-category APr is 14.4 vs. 17.7.
- The gain from adding Cap4M is +1.8 for Grounding DINO and +1.1 for GLIP, from which the authors conclude that their model makes better use of more data.
The authors went through LVIS results from several DETR-family models and found that all of them score low on rare categories, so they suspect a limitation of this kind of architecture itself. Another point of comparison is DetCLIPv2 with Swin-T, which uses larger caption data (CC15M) and scores 40.4 zero-shot, higher even than Grounding DINO L's 33.9.
ODinW: Mean and Median
ODinW collects 35 small real-world datasets, ranging from drone aerial imagery to plant diseases. In the zero-shot setting, Grounding DINO T (with Cap4M) has a mean AP of 22.3, the same as GLIPv2-T; but its median is 11.9, against only 8.9 for GLIPv2-T. With the same mean and a higher median, it is steadier across datasets rather than propped up by a few of them.
Grounding DINO L's zero-shot mean is 26.1, above Florence's 25.8.
Beneath the mean, individual domains can still fail completely. In the per-dataset results in the appendix, PlantDoc (plant diseases) gets only 0.36 AP, and GLIP only 1.1. Category names like "tomato leaf mosaic virus" hardly ever appear in the pre-training data.
REC: It Can Box Objects, but Can't Read Sentences

Referring expression comprehension asks for one box per phrase. In the figure above, given "guy with cow," the model boxes every noun that appears in the phrase, two boxes for "guy" and one for "cow"; it can find the things, but it hasn't understood that "with cow" specifies which guy.
The accuracy numbers match this behavior. Pre-trained on O365 and GoldG only, Grounding DINO T has a top-1 accuracy of 50.41 on RefCOCO val, against 49.96 for GLIP-T(B) under the same conditions, both only around fifty percent. Adding RefC to pre-training raises it to 73.98; only after fine-tuning on RefCOCO does it reach 89.19, surpassing DQ-DETR (88.63), previously the best in the table.
The authors also tried replacing BERT-base with BERT-large, which actually scored slightly lower on RefCOCO val (87.0 vs. 87.4). Their reading is that the REC bottleneck lies in the detection branch, and the text encoder is already good enough.
More Data Isn't Always Better
Table 6 looks at the effect of adding RefC and COCO, all three runs with Swin-T:
| Pre-training data | COCO zero-shot | LVIS zero-shot | ODinW zero-shot |
|---|---|---|---|
| O365, GoldG | 48.1 | 25.6 | 20.0 |
| +RefC | 48.5 | 21.9 | 17.7 |
| +RefC, COCO | 56.1 | 22.3 | 17.4 |
Compiled from Table 6 of the paper. Once COCO is added, the COCO score is no longer zero-shot.
RefC's images all come from COCO. Adding it raises the COCO score, but LVIS and ODinW both drop. Teaching the model the extra skill of "one phrase, one box" costs it open detection ability on other datasets.
Ablation: Each of the Three Fusions Contributes
| No. | Model | COCO zero-shot | COCO fine-tuned | LVIS zero-shot |
|---|---|---|---|---|
| 0 | Full model | 46.7 | 56.9 | 16.1 |
| 1 | No encoder fusion | 45.8 | 56.1 | 13.1 |
| 2 | Static query selection | 46.3 | 56.6 | 13.6 |
| 3 | No text cross-attention | 46.1 | 56.3 | 14.3 |
| 4 | Word-level prompt | 46.4 | 56.6 | 15.6 |
Compiled from Table 7 of the paper; all pre-trained on O365 only, with Swin-T.
These experiments all use O365 only, so the COCO zero-shot gaps range from a few tenths to 0.9, and the differences only show on LVIS. Removing encoder fusion hurts the most, costing 3.0 on LVIS; going back to static query selection costs 2.5, removing the text cross-attention in the decoder costs 1.8, and sub-sentence contributes the least, 0.5.
The gaps in the fine-tuned COCO scores are all small. Query selection and the sub-sentence mask add no parameters and make almost no difference after fine-tuning; encoder fusion and text cross-attention do add parameters, and removing them costs more. From this the authors infer that fine-tuned performance is mainly determined by parameter count.
The Cost
Open-set ability has its cost. In the appendix, with pure closed-set training on COCO using ResNet-50 for 12 epochs, Grounding DINO scores 48.1 AP against 49.0 for the original DINO. The authors suspect that the extra modules make the model harder to optimize.
On speed, the authors compare only with GLIP-T. Grounding DINO T has 172M parameters, 464 GFLOPs and 8.37 FPS, while GLIP-T has 232M, 488 GFLOPs and 6.11 FPS; the paper doesn't say what hardware the speed was measured on. Neither is anywhere near real time, which is the problem YOLO-World later set out to solve.
If you already have a trained DINO, the appendix also offers a cheaper route. Freeze the modules that DINO and Grounding DINO share and train only the text branch and the fusion modules, and you get 46.4 on COCO zero-shot, 26.1 on LVIS and 18.5 on ODinW, each a little above or below the 48.1, 25.6 and 20.0 from training from scratch, with faster convergence too.
Limitations and What Came Next
In the conclusion the authors list three limitations, namely that it can't do segmentation, that its training data is smaller than the largest GLIP's, and that it produces false positives. False positives are the problem you run into most in practice; even when the thing named in the prompt is plainly absent from the image, the model may still give it a fairly high score. The official documentation also points out that the model always outputs 900 boxes, and the thresholds decide which ones stay.
Another issue is how much was open-sourced. The official release includes only inference code and weights, with no training code. In January 2024, a team rebuilt it in MMDetection as MM-Grounding-DINO, and their abstract states outright that the original lacks complete technical details because its training code was never released. Cap4M wasn't released either, so they used GRIT and V3Det instead.
Conclusion
Bringing language into the detector at all three points is the paper's core claim, and the layer-by-layer attention structure of the DETR family is what makes it possible. The ablations support the claim, since removing any one of the three fusion points lowers the LVIS score; its 52.5 COCO zero-shot and 26.1 ODinW were the best results at the time. Its weaknesses are just as clear, with rare categories, referring expressions and false positives all still unsolved.
If you use it yourself, write prompts in the cat . dog . person . format, and always separate categories with periods; for the thresholds, start tuning from the official 0.35 and 0.25. If you really need segmentation masks, the common approach is to hand its boxes to SAM, which is what later became Grounded SAM.
A little over a year later, the same team released Grounding DINO 1.5, with the data scaled up to more than twenty million images with grounding annotations and 55.7 zero-shot on LVIS.
This time not even the weights were released, only an API.