The detector in the recognition lesson knows 80 words. Ask it for a croissant and it has nothing to say: COCO, its training set, has donuts and cakes but no croissants. CLIP, from images and words, knows almost any word, but it describes the whole picture and cannot say where anything is.
Put the two together and you get a detector that boxes whatever you name. You type the words; it decides where each one is. This is Open-vocabulary detectionObject detection where the kinds of object to find are given as text at run time, so the detector can box things named by any word or phrase rather than a fixed list of labels.Open in glossary, and the model here, OWL-ViT (Matthias Minderer and colleagues at Google, 2022), is one of the simplest ways to do it.
Every patch, scored against every word
OWL-ViT starts from CLIP: an image encoder and a text encoder trained so that pictures and their captions land close together. It changes only the end of the image side.
- The image is stretched to 768 × 768 pixels and cut into 24 × 24 = 576 patches of 32 pixels, as in how computers see.
- CLIP would pool the 576 output tokens into one vector for the whole picture. OWL-ViT keeps all of them. Each token gets a box, from a small network, and an embedding of what is in that box.
- Each word you type goes through the text encoder on its own and becomes one embedding.
- Every patch’s embedding is compared with every word’s: a Cosine similarityA measure of how closely two vectors point in the same direction, from -1 (opposite) through 0 (perpendicular) to 1 (same direction), ignoring their lengths.Taught in Vectors and similarityOpen in glossary, adjusted by a shift and a scale that the model computes for each patch, then squashed by a SigmoidThe S-shaped function 1 / (1 + e^-z), which squashes any number into the range 0 to 1 so it can be read as a probability.Taught in Classification and probabilityOpen in glossary into a score between 0 and 1.
So the model always makes 576 predictions, one per patch, and the words decide what they are called. Each prediction keeps the word that scores it highest, and the threshold decides which predictions you see.
Find anything you can name
Type words, and an open-vocabulary detector boxes whatever matches each one. No fixed list of labels.
Words to find (3 of 8)
- croissant
- coffee cup
- spoon
Your photos and camera frames are processed on this device and never uploaded.
Loading the recorded results
Challenges
0 of 3 complete
- With the threshold at 30% or more, box both croissants on the breakfast table. The 80-label detector from the recognition lesson has no word for them. (not yet)
- At a threshold of 10% or more, find two words the detector accepts for the same object whose scores differ by more than 15 points. (not yet)
- Get a word to lose its best box to another word, even though it scores above the threshold there. (not yet)
Try this
- On the breakfast table, raise the threshold to 30% and look at the croissants. Then try “elephant”.
- Add “cup” next to “coffee cup”. Before you look, predict which word keeps the box.
- On the motorcycle, compare “cat” with “kitten”, and “motorcycle” with “moped”.
- On the dog, try “dog” and then “boxer”, the label the classifier gave it at 77%.
- Try the corridor and the woodblock print with the suggested words. Then type the names of things around you with the camera.
What the scores mean
The two croissants score 54% and 53%. At 10%, the lower one also gets two smaller boxes over its halves and a near copy of its whole box: the partial boxes and duplicates a low threshold lets through.
Each word is scored on its own. The softmax in the recognition lesson shared one unit of probability among 1,000 labels, so a picture of nothing in particular still gave some label most of it. Here a box can score high for several words at once or for none: “elephant” never reaches 1% on the breakfast table. On the cup’s box, “coffee cup” and “cup” together score 0.93, more than any probability could.
Wording matters as much as it did for CLIP’s prompts. The same box scores 60% as “coffee cup” and 33% as “cup”; the cat on the motorcycle is 64% “cat” and 47% “kitten”. The dog that the classifier called a boxer at 77% is 20% “dog” to this model and 2% “boxer”. A score says how well the box matches this wording, so a threshold that suits one word can hide another.
Words also compete. Each prediction keeps only its best word, so with “coffee cup” and “cup” both typed, the box where “cup” scores 33% is shown as “coffee cup” at 60%. Adding a word can take boxes away from another.
How it was trained, and how it fails
This model’s encoders are OpenAI’s CLIP ViT-B/32, pretrained on 400 million pictures and captions from the web. The OWL-ViT authors added the box and embedding heads and fine-tuned everything end to end on public detection datasets of about 2 million images, such as Objects365 and Visual Genome. During fine-tuning, each image’s category names are the words, and each labeled object is matched to exactly one prediction, the training method of DETR from the recognition lesson.
To measure zero-shot detection, the authors removed every box of LVIS’s rare categories from the training data. LVIS has 1,203 categories, so any success on the rare ones comes from the image-text pretraining. In the paper, the B/32 model built on CLIP, the configuration of the model in this lab, scored 22.1 average precision on all of LVIS and 18.9 on the rare categories it had never been shown a box for. The checkpoint the authors released, which this lab runs, scores lower in their repository’s own evaluation: 16.9 on the rare categories.
The failures in the lab have the same causes as before. On the corridor, “pillar” stays under 1% though the photo is full of pillars, and the bird in the woodblock print reaches only 9%: both pictures are unlike most training photos. The cat lying across the whole frame of its photo gets 12% as “cat”, while the small cat on the motorcycle gets 64%. The model’s own card describes it as a research model, meant for studying exactly these behaviors.
Scoring every patch against every wordPython with NumPy
import numpy as np
def unit(v):
return v / np.linalg.norm(v, axis=-1, keepdims=True)
def sigmoid(x):
return 1 / (1 + np.exp(-x))
# Made-up embeddings in 3 numbers (OWL-ViT B/32 uses 512): one per image
# patch from the image encoder, one per typed word from the text encoder.
patches = unit(np.array([[0.9, 0.3, 0.1], # a patch on a cup
[0.5, 0.8, 0.1], # a patch on a croissant
[0.1, 0.2, 1.0]])) # a patch on the table
words = ["coffee cup", "cup", "croissant"]
texts = unit(np.array([[1.0, 0.25, 0.0],
[0.9, 0.2, 0.4],
[0.45, 0.9, 0.0]]))
# Every patch scores every word on its own: cosine similarity, a shift and a
# scale (learned for each patch in the real model, fixed here), a sigmoid.
scores = sigmoid((patches @ texts.T - 0.85) * 20)
print("scores (rows are patches):")
print(np.round(scores, 2))
print("row sums:", np.round(scores.sum(axis=1), 2)) # not 1: no softmax
# Each patch keeps only its best word, and only above the threshold.
for p, row in enumerate(scores):
best = row.argmax()
if row[best] >= 0.1:
print(f"patch {p}: {words[best]} {row[best]:.2f}")
else:
print(f"patch {p}: nothing above 0.10")scores (rows are patches):
[[0.94 0.88 0.05]
[0.06 0.03 0.94]
[0. 0. 0. ]]
row sums: [1.87 1.04 0. ]
patch 0: coffee cup 0.94
patch 1: croissant 0.94
patch 2: nothing above 0.10OWLv2, and why this lab uses the older modelOptional
OWLv2 (Minderer, Gritsenko, and Houlsby, 2023) keeps the architecture and changes the data. An existing detector labels over a billion image and caption pairs from the web with pseudo-boxes, and the model trains on those. On LVIS’s rare categories, average precision rose from 31.2 to 44.6 for the largest model.
The base OWLv2 model reads images at 960 × 960 pixels in 16-pixel patches: 3,600 patches against this model’s 576, and attention’s cost grows with the square of that count. Measured on the same computer with 8-bit weights for both, it took more than ten times as long per photo: about 10 seconds against 0.7. At about a second per photo in the browser, OWL-ViT B/32 can follow a live camera; OWLv2 could not.
The lab also uses 16-bit weights (311 MB) rather than the 8-bit version (155 MB). On the sample photos, 8-bit weights moved scores by up to 18 points and moved some boxes by hundreds of pixels, the kind of damage the quantization lesson describes; 16-bit matched the full-precision model to within about half a point.
Key ideas
- An open-vocabulary detector keeps one prediction per image patch and scores each against every word you type, so the labels are whatever words you choose.
- Each word’s score is an independent sigmoid, not a share of one probability: several words can score high on one box, and every word can score near zero.
- Scores depend on wording, and each prediction keeps only its best word, so words compete for boxes.
- OWL-ViT starts from CLIP’s image-text training and is fine-tuned on detection data; zero-shot detection is measured on categories whose boxes were removed from training.
- It fails where CLIP does: unusual pictures, rare words, and objects that fill the frame.
Sample photos, all CC0 on Wikimedia Commons: Dog by Joselodos; Cat by Vyshnavi medicharla; Cat on a motorcycle by CAPTAIN RAJU; Breakfast by Andy Li; Street by Mucklagh; Cafe by Andy Li; Corridor by Sindugab; Woodblock print by Utagawa Hiroshige (Metropolitan Museum of Art).