Skip to content
AI360Xpert
Beta

Grounding DINO Detects What Words Name

Grounding DINO guides detector queries with text, so each query hunts a phrase-named object. Language picks which image spots become boxes.

Text scores rank nine hundred query spots, the top hundred decode with image and word fusion, and the best box names its phrase.
Text scores rank nine hundred query spots, the top hundred decode with image and word fusion, and the best box names its phrase.

Why Does This Exist?

A closed-set detector only names the classes it trained on: show it a rare animal and it reports the nearest familiar label or nothing. DETR removed anchors but kept this closed vocabulary, with queries that learn dataset-common spots. Grounding DINO (Liu et al., 2023) conditions those queries on free text instead, so a new phrase retrieves its own boxes without retraining.

This page covers the text-guided query selection and the fused decoder. The general detection setup lives in object detection, the set-prediction machinery in DETR, and the evaluation framing in open-vocabulary detection.

Think of It Like This

Sniffer dogs briefed with a scent cloth

Dogs running free quarter the whole field and flush whatever is common there. Press a scent cloth to their noses first and each team works only ground matching that scent, ignoring familiar but irrelevant trails. The cloth does not teach them to smell; it tells them what is worth finding today.

Queries are the dogs, the phrase embedding is the scent cloth, and dot-product similarity picks the field. Where it stops: a vague cloth confuses every team at once, just as a twenty-word phrase dilutes similarity and scatters the queries.

How It Actually Works

An image encoder produces visual features vv and a text encoder produces phrase features tt. Every candidate spot scores sim(v,t)=v⋅t\text{sim}(v, t) = v \cdot t against the phrase, and only the top spots, 100100 of 900900 in the standard setting, become decoder queries. The decoder then fuses all three streams with self-attention plus image and text cross-attention, and each query outputs a box plus a phrase-alignment score. Training pays box L1L_1 plus GIoU plus phrase classification jointly, after pretraining on a grounding mix of Objects365, GoldG, and Cap4M that pairs regions with words at scale.

Worked example

Four candidate spots face the phrase vector t=[0.6,0.8]t = [0.6, 0.8]. Dots by hand: v1=[0.7,0.7]v_1 = [0.7, 0.7] gives 0.6⋅0.7+0.8⋅0.7=0.42+0.56=0.980.6 \cdot 0.7 + 0.8 \cdot 0.7 = 0.42 + 0.56 = 0.98; v2=[0.1,0.2]v_2 = [0.1, 0.2] gives 0.06+0.16=0.220.06 + 0.16 = 0.22; v3=[0.9,0.1]v_3 = [0.9, 0.1] gives 0.54+0.08=0.620.54 + 0.08 = 0.62; v4=[0.2,0.9]v_4 = [0.2, 0.9] gives 0.12+0.72=0.840.12 + 0.72 = 0.84. Ranking: 0.98>0.84>0.62>0.220.98 > 0.84 > 0.62 > 0.22, so the top two queries start at v1v_1 and v4v_4. The v1v_1 box lands at IoU 0.780.78 with the truth, against 0.310.31 for a text-blind pick at v3v_3, and its training loss totals 0.12+0.25+0.40=0.770.12 + 0.25 + 0.40 = 0.77 across L1L_1, GIoU, and phrase terms. Text selection cuts exactly the 0.310.31 misses that blind queries keep.

Code

Pure Python, no imports: score four spots against the phrase, keep the top two, and total the fixture loss.

t = [0.6, 0.8]spots = {"v1": [0.7, 0.7], "v2": [0.1, 0.2], "v3": [0.9, 0.1], "v4": [0.2, 0.9]}
scores = {k: t[0] * v[0] + t[1] * v[1] for k, v in spots.items()}ranked = sorted(scores, key=scores.get, reverse=True)print({k: round(scores[k], 2) for k in ranked})# -> {'v1': 0.98, 'v4': 0.84, 'v3': 0.62, 'v2': 0.22}print(ranked[:2])# -> ['v1', 'v4']
loss = 0.12 + 0.25 + 0.40  # L1 + GIoU + phrase classificationprint(round(loss, 2))# -> 0.77

Top two queries v1v_1 and v4v_4 by text similarity, loss 0.770.77: the ranking the prose derived by hand, confirmed.

Watch Out For

Long phrases scattering the queries

Twenty-word phrases dilute similarity and the queries scatter across the image. The symptom is grounding accuracy sagging on long referring expressions while short nouns work fine. Shorten prompts to nouns plus relations, or weight noun tokens higher in the text encoder, before blaming the detector.

Treating phrase scores as calibrated confidence

Phrase-alignment scores rank boxes within one image but are not calibrated probabilities across phrases. The symptom is a fixed threshold keeping junk for common words while dropping good boxes for rare ones. Calibrate per phrase or report recall at fixed top-kk instead of thresholding raw scores.

The Quick Version

  • Grounding DINO scores 900900 candidate spots by text similarity and decodes only the top 100100.
  • Image plus text fusion shapes each box through self, image, and text cross-attention.
  • The fixture ranks spots 0.98>0.84>0.62>0.220.98 > 0.84 > 0.62 > 0.22 and the winner lands at IoU 0.780.78 against 0.310.31 blind.
  • Box L1L_1 plus GIoU plus phrase loss train jointly, totaling 0.770.77 on the fixture.
  • Broad grounding mixes of Objects365, GoldG, and Cap4M supply the open phrases; long prompts and raw thresholds are the two classic failures.