Skip to navigation

Predict OWLv2

Runs on: gpu Dockerfile
First run can take longer while the worker pulls the configured Docker image.

Overview

Detects objects across a dataset’s images with OWLv2, Google’s open-vocabulary detector, or its first version OWL-ViT, and saves the boxes as annotations in the output dataset. It needs no training: you describe what to find, by class name, by a few labeled examples, or by both.

Labeled examples are the way to find things a name does not describe well: a specific part, a defect, a product, a species. Label a few objects of each class in a small dataset, pick it as Reference images, and the node finds objects that look like them.

Reference images Predict OWLv2 Dataset Labeling

Pretrained models

ModelInput sizeLVIS APr
OWLv2 B/16960 px40.5
OWLv2 L/141008 px42.6
OWL-ViT B/32768 px16.9
OWL-ViT B/16768 px17.1
OWL-ViT L/14840 px31.2

APr is the AP on LVIS’s rare classes, which none of these models was trained on, from the OWL-ViT authors’ table.

Prerequisites

RequirementWhat you need
GPU workerA worker with a GPU.
Image datasetAn existing Dataset with images.
Reference images (optional)A dataset with a few images on which every object of each class is labeled with a box, for Visual examples and Class names and visual examples.

How it works

1

Resolves what to detect: the picked classes, or for visual examples every class labeled in the reference images, and a few labeled boxes of typical size from each reference image.

2

Creates the output dataset, adds the source images to it and pins it to the classes being detected.

3

Loads the model and turns each prompt into a query: a class name as “a photo of a …”, a labeled example as what the model sees inside its box on the reference image, measured against how much the rest of that image already resembles it.

4

Scores every box the model proposes on each image against every query, keeps the boxes that clear the threshold of their prompt kind, and removes overlapping duplicates within a class.

5

Writes the boxes as annotations and shows how many images were annotated on the badge.

FAQ

No. Predictions land in the output dataset, and both source datasets keep what they had.

Class names work for everyday objects with plain names. Examples work when the name is ambiguous, internal or too specific for the model to know: label a few objects and the model looks for that appearance. Class names and visual examples gives each class both, and a box counts for a class when it matches either.

One per class can work, and a handful covering the different ways the class looks works better. Examples per class caps how many are used. The node takes the boxes closest to the class’s typical size, one reference image after another, so an oversized box such as a clump of touching objects does not become an example and no single image dominates.

The picked Classes, or when none is picked, every class labeled in the reference images. A picked class with no labeled example there is reported in the log and can be found only by its name, in Class names and visual examples.

A box scores on a different scale against a class name than against an example. OWL-ViT rates almost any region as close to an example, so an example’s score says how much more a box looks like it than anything unlabeled on the example’s own image does. Lower text_threshold or visual_threshold in Config when the node misses objects, and raise it when it finds too much.

The unlabeled part of a reference image is what its examples are compared against. An object of the class left unlabeled there looks exactly like the example, so it raises the bar every match has to clear and the node finds less.

The model proposed nothing that overlaps the labeled box well, so the query may describe the surroundings instead of the object. A tighter box around the object, or a larger example, fixes it.

Videos: it annotates images only, so sample frames from videos into an image dataset first. It does not train or fine-tune the model, and it draws boxes, not masks.

Run Evaluate object detection against a ground-truth dataset. Prediction alone reports how many images were annotated, not how correct the annotations are.

Inputs

Dataset
datasetRequired

Dataset whose images are annotated. Key: DATASET.

Destination dataset
dataset

Dataset the predictions are added to, keeping what it already holds. An image it already annotates gets the new prediction instead. Leave empty to use the node’s own output dataset, which a rerun writes a new version of. Key: DST_DATASET.

Model
modelRequired

OWLv2 or OWL-ViT weights, from this workspace or the zoo. OWLv2 finds noticeably more than the original OWL-ViT, the L/14 models find more again, at about three times the GPU time of B/16. Key: MODEL.

Prompt
selectDefaults to textRequired

How the classes to detect are described. Class names asks for each class by its name. Visual examples shows the model labeled objects from the reference images and finds objects that look like them, which works for things a name cannot describe. Both uses the name and the examples of each class together. Key: PROMPT_MODE.

Options:

  • Class names (text)
  • Visual examples (visual)
  • Class names and visual examples (both)
Classes
ontology

Classes to detect. Class names needs at least one, type a name to add a class the ontology does not have yet. With visual examples, leave it empty to detect every class labeled in the reference images, or pick some to detect only those. Key: CLASSES.

Reference images
dataset

Labeled images the visual examples are taken from: each box is an example of its class, typical-sized ones first, spread across the images. Label every object of a class on these images: the rest of the image is what an example is compared against, so an unlabeled one counts against it. A few images with a handful of boxes per class are enough. Visible when PROMPT_MODE is not text. Key: REFERENCE_DATASET.

Examples per class
integerDefaults to 8Required

Labeled objects of each class used as visual examples: those closest to the class’s typical size, taken in turn from each reference image. More examples cover more of the ways a class can look, and each one adds a reference image to process. Minimum: 1. Maximum: 64. Step: 1. Visible when PROMPT_MODE is not text. Key: EXAMPLES_PER_CLASS.

Config
yamlRequired

Inference settings in YAML. A box is kept when it scores at least text_threshold against a class name or visual_threshold against an example. An example’s score says how much more the box looks like it than anything unlabeled on the example’s own image does, so the two run on different scales and each has its own threshold. nms_iou is how much two boxes of a class may overlap before the weaker one is dropped, max_detections caps the boxes of one image, and batch_size is how many images go through the GPU at once. Key: CONFIG.

Download batch size
integerDefaults to 64Required

Number of images fetched at a time while the GPU works through the ones already downloaded. Minimum: 1. Key: DOWNLOAD_BATCH_SIZE.

Prefetch batches
integerDefaults to 4Required

How far downloading may run ahead of inference, counted in batches. Raise it when a slow connection leaves the GPU idle, at the cost of disk space. Minimum: 1. Key: PREFETCH_BATCHES.

Outputs

Output Dataset
dataset

Dataset with the input images plus the predicted boxes: the destination dataset when one is picked, otherwise the node’s own. Shown as an artifact. Key: OUTPUT_DATASET.

Predicted
string

Number of images annotated. Shown on the node as a badge. Selecting the badge opens OUTPUT_DATASET. Key: PRED_COUNT.

Models and configuration

Model is the one place the weights come from: a model of this workspace, or one of the zoo entries listed above, whose safetensors the node downloads from Google’s Hugging Face release and checks before loading. OWLv2 finds noticeably more than the original OWL-ViT, and the L/14 models find more again, at about three times the GPU time of B/16.

The output dataset is pinned to the classes the predictions are named in. Picked classes keep their ontology, and with visual examples and no classes picked, the output follows the reference images’ ontology. A shared ontology can’t be assigned to a dataset, so classes picked from one are saved as a version of the workspace’s OWLv2 prompts ontology instead. A destination dataset that already has an ontology keeps it and only gains the detected classes.

Config holds the inference settings: text_threshold and visual_threshold, the scores a box needs against a class name or an example, both set where precision and recall balanced on COCO images; nms_iou, how much two boxes of a class may overlap before the weaker is dropped; max_detections, the cap per image; and batch_size, how many images go through the GPU at once. When a batch does not fit in GPU memory, the run halves it and carries on.

Runtime

The node runs in its own GPU container, in half precision. The first run takes longer while the worker pulls the image and downloads the selected weights.

Images are fetched ahead of the model and decoded on all the machine’s CPUs while the GPU works. Download batch size sets how many arrive at once and Prefetch batches how many wait on local disk. Each image is deleted from disk once it is decoded.

JSON config

Machine-readable node interface for automation and advanced usage.

{
"name": "Predict OWLv2",
"description": "Detect objects with OWLv2 or the original OWL-ViT, prompted by class names, by labeled examples of each class, or both, and write the boxes into the output dataset.",
"category": "Predict",
"namespace": "ovalbee",
"templateKey": "models/owl_vit/predict_owlv2",
"version": "v1",
"inputs": [
{
"key": "DATASET",
"label": "Dataset",
"type": "dataset",
"description": "Dataset whose images are annotated.",
"required": true,
"default": null,
"visibleWhen": null,
"options": {
"creatable": false
}
},
{
"key": "DST_DATASET",
"label": "Destination dataset",
"type": "dataset",
"description": "Dataset the predictions are added to, keeping what it already holds. An image it already annotates gets the new prediction instead. Leave empty to use the node's own output dataset, which a rerun writes a new version of.",
"required": false,
"default": null,
"visibleWhen": null
},
{
"key": "MODEL",
"label": "Model",
"type": "model",
"description": "OWLv2 or OWL-ViT weights, from this workspace or the zoo. OWLv2 finds noticeably more than the original OWL-ViT; the L/14 models find more again, at about three times the GPU time of B/16.\n",
"required": true,
"default": null,
"visibleWhen": null,
"options": {
"framework": "owl_vit",
"task_type": "object_detection"
}
},
{
"key": "PROMPT_MODE",
"label": "Prompt",
"type": "select",
"description": "How the classes to detect are described. Class names asks for each class by its name. Visual examples shows the model labeled objects from the reference images and finds objects that look like them, which works for things a name cannot describe. Both uses the name and the examples of each class together.\n",
"required": true,
"default": "text",
"visibleWhen": null,
"options": {
"options": [
{
"label": "Class names",
"value": "text"
},
{
"label": "Visual examples",
"value": "visual"
},
{
"label": "Class names and visual examples",
"value": "both"
}
]
}
},
{
"key": "CLASSES",
"label": "Classes",
"type": "ontology",
"description": "Classes to detect. Class names needs at least one; type a name to add a class the ontology does not have yet. With visual examples, leave it empty to detect every class labeled in the reference images, or pick some to detect only those.\n",
"required": false,
"default": null,
"visibleWhen": null,
"options": {
"selectable": true,
"creatable": true
}
},
{
"key": "REFERENCE_DATASET",
"label": "Reference images",
"type": "dataset",
"description": "Labeled images the visual examples are taken from: each box is an example of its class, typical-sized ones first, spread across the images. Label every object of a class on these images: the rest of the image is what an example is compared against, so an unlabeled one counts against it. A few images with a handful of boxes per class are enough.\n",
"required": false,
"default": null,
"visibleWhen": {
"key": "PROMPT_MODE",
"operator": "notEquals",
"value": "text"
},
"options": {
"creatable": false
}
},
{
"key": "EXAMPLES_PER_CLASS",
"label": "Examples per class",
"type": "number",
"description": "Labeled objects of each class used as visual examples: those closest to the class's typical size, taken in turn from each reference image. More examples cover more of the ways a class can look, and each one adds a reference image to process.\n",
"required": true,
"default": 8,
"visibleWhen": {
"key": "PROMPT_MODE",
"operator": "notEquals",
"value": "text"
},
"options": {
"type": "integer",
"min": 1,
"max": 64,
"step": 1
}
},
{
"key": "CONFIG",
"label": "Config",
"type": "yaml",
"description": "Inference settings in YAML. A box is kept when it scores at least text_threshold against a class name or visual_threshold against an example. An example's score says how much more the box looks like it than anything unlabeled on the example's own image does, so the two run on different scales and each has its own threshold. nms_iou is how much two boxes of a class may overlap before the weaker one is dropped, max_detections caps the boxes of one image, and batch_size is how many images go through the GPU at once.\n",
"required": true,
"default": "text_threshold: 0.2\nvisual_threshold: 0.5\nnms_iou: 0.3\nmax_detections: 300\nbatch_size: 2\n",
"visibleWhen": null
},
{
"key": "DOWNLOAD_BATCH_SIZE",
"label": "Download batch size",
"type": "number",
"description": "Number of images fetched at a time while the GPU works through the ones already downloaded.",
"required": true,
"default": 64,
"visibleWhen": null,
"options": {
"type": "integer",
"min": 1
}
},
{
"key": "PREFETCH_BATCHES",
"label": "Prefetch batches",
"type": "number",
"description": "How far downloading may run ahead of inference, counted in batches. Raise it when a slow connection leaves the GPU idle, at the cost of disk space.",
"required": true,
"default": 4,
"visibleWhen": null,
"options": {
"type": "integer",
"min": 1
}
}
],
"outputs": [
{
"key": "OUTPUT_DATASET",
"label": "Output Dataset",
"type": "dataset",
"description": "Dataset with the input images plus the predicted boxes: the destination dataset when one is picked, otherwise the node's own.",
"artifact": true,
"badge": false,
"badgeOpens": null,
"hidden": false
},
{
"key": "PRED_COUNT",
"label": "Predicted",
"type": "string",
"description": "Number of images annotated.",
"artifact": false,
"badge": true,
"badgeOpens": "OUTPUT_DATASET",
"hidden": false
}
],
"runtime": {
"type": "docker",
"devices": [
"gpu"
],
"dockerImage": "ovalbee/node-owl-vit:0.0.2"
},
"widgets": {
"widget": {
"id": "asset-preview",
"settings": {
"datasetId": {
"type": "variable",
"value": "self.outputs.OUTPUT_DATASET"
}
}
}
}
}

References