Software

Published

How Prompt2Box locates objects from a text prompt

BY

Jin Tan Ruan

Jin Tan Ruan

Prompt2Box turns a text prompt and an image into bounding boxes for matching objects. Changing the prompt lets a team test a new object category without collecting a training set for it. The library compares predicted boxes with human annotations to measure missed objects, false detections, and how closely each box fits. For a fixed set of objects, we recommend comparing detection quality, latency, and cost on representative images before choosing a detector.

Aerial view of cars and buildings around a large city intersection.

Abstract

A pretrained Gemini model can return labeled bounding boxes for an image from a natural-language instruction, with no additional task-specific training dataset or detector fine-tuning, and no fixed class list. This article traces four phases of object detection, describes the response format (a label and a box_2d of four integers normalized to a 0-1000 grid in (y, x) order), and compares the approach with trained detectors across ten dimensions.

Trained detectors remain preferable for high-volume, fixed-class, low-latency detection that needs tight boxes. Prompt-defined detection suits long-tail or changing classes and the early validation of a use case. The article also introduces Prompt2Box, an open-source library that packages the integration details, and a five-stage reference pipeline. Gemini bounding box detection is a Pre-GA (experimental) feature.

Introduction

Computer vision teams have always paid an overhead to answer a simple question: where the objects in an image are. Historically, drawing a labeled box around each object meant collecting a dataset, writing annotation guidelines, training a model, standing up a serving stack, and committing in advance to a fixed list of classes. With multimodal models, that workflow is changing. An image and a natural-language instruction can now be sent to Gemini, which returns labeled bounding boxes - no additional task-specific training dataset or detector fine-tuning, and no fixed class list.

This article examines how object detection evolved to this point, how Gemini's bounding box detection (spatial understanding) works, where it fits relative to traditional computer vision, and how it can be put into production. It also introduces Prompt2Box, an open-source library that packages the integration details so that the capability can be adopted with a single import.

The cited documentation describes bounding-box detection as a Pre-GA capability. Structured output, evaluation gates, and hybrid pipelines can help manage errors. They do not establish suitability for a particular deployment.

Background: A Brief History of Object Detection

Object detection has always combined two tasks: localization (where an object is, expressed as a box) and classification (what the object is, expressed as a label). The way the field has solved those tasks has moved through four phases, summarized in Figure 1, and the common thread is that each phase moved more of the required prior knowledge from the engineer to the model.

Four phases of object detection
Figure 1. The four phases of object detection, from hand-crafted features to multimodal models.

Hand-Crafted Features (2001-2013)

Early detection relied on features that humans designed by hand. Viola-Jones (2001) made real-time face detection practical with Haar-like features and a cascade of weak classifiers. HOG with a linear SVM (2005) generalized the approach and underpinned a generation of pedestrian detectors. Deformable Part Models treated an object as a constellation of parts. In every case, a human decided what a feature was, and adding a new class meant new engineering.

Learned Features and CNN Detectors (2014-2019)

Deep learning replaced hand-designed features with features learned from labeled data. The R-CNN family (2014-2015) introduced two-stage detection: propose regions, then classify them. YOLO and SSD (2016) reframed detection as a single pass over a grid, trading some accuracy for speed - the lineage that still runs on edge devices and factory cameras today. RetinaNet (2017) addressed class imbalance, and Mask R-CNN extended boxes to pixel-level masks. These detectors are fast, cheap per inference, deterministic, and accurate, but they share one constraint: a closed vocabulary. A model can only detect the classes it was trained on, and a new class means relabeling and retraining.

Transformers and Open-Vocabulary Detection (2020-2023)

Two ideas removed the closed-vocabulary ceiling. DETR (2020) recast detection as set prediction with a transformer, removing anchors and post processing. Vision-language models then tied detection to natural language: CLIP (2021) aligned images and text in a shared embeddings space, and detectors such as GLIP, OWL-ViT, and Grounding DINO extended that alignment to the region level, so that a class could be detected by describing it rather than by training on it. (SAM added promptable segmentation in the same period, though it is prompted by points and boxes rather than language.) Detection moved from "choose from a fixed class list" to "ground this phrase in this image."

Detection with Multimodal Models (2023-Present)

Multimodal large language models, including Gemini, absorbed grounding into a general reasoning engine. The model already understands an image well enough to answer questions about it, so returning coordinates is one more output format. Because the interface is natural language, the class taxonomy is no longer a configuration decided up front - it is an instruction supplied at request time.

Method: Bounding Box Detection with Gemini

Gemini receives a prompt and one or more images or video frames. For each detected object, the model returns two fields:

  • The label field is a short string. The vocabulary is open, so a label can be "car" or "the rusty bicycle leaning on the left wall," depending on the instruction.

  • The box_2d field holds four integers, [y_min, x_min, y_max, x_max], normalized to a 0-1000 grid with the origin at the top-left corner.

Two details matter when this output is integrated, and they are summarized with the response format in Figure 2:

  • Coordinate order is (y, x), not (x, y). Most tooling (OpenCV, Pillow) expects (x_min, y_min, x_max, y_max). Gemini returns row-major (y, x), so the pairs must be swapped or the boxes will be transposed.

  • Coordinates are normalized to 0-1000, not pixels. Rescaling to a given image uses x_px = x_norm / 1000 * width. The same response maps onto a thumbnail or a full-resolution original, but the original dimensions are needed to draw boxes.

Gemini bounding box response format
Figure 2. The Gemini bounding box response format and the conversions required by most tooling.

A JSON response schema defines the expected labels and box fields, making responses easier to parse and validate. Schema conformance does not establish that a detection is correct. The following example uses the google-genai SDK for Python.

The response_schema parameter is what turns a model that usually returns JSON into an API that returns a typed list of bounding boxes.

Analysis: Practical Trade-offs

Prompt2Box provides a prompt-based route to object localization without task-specific detector training. This article does not compare its box quality with a trained detector on a shared reviewed dataset.

Taxonomy Defined at Request Time

Traditional detection forces an early, hard-to-reverse decision about which classes the model will know. With Gemini, the taxonomy is a string in the request. The same endpoint can detect "forklift" today and "spilled liquid on the warehouse floor" tomorrow, with no retraining or redeployment. For businesses whose objects of interest change with the season, the catalog, or a regulation, this is a significant simplification.

Detection by Instruction

A conventional detector recognizes "person." Gemini can detect "employees not wearing a hard hat," because it reasons over the scene rather than matching a single class. Conditions and relationships can be detected - an open drawer, damaged packaging, an expired sign - which moves detection from object presence toward situation understanding.

Cost Shifted from Up-Front to Per-Use

Prompt-based detection can support an initial prototype without task-specific detector training. Validating a use case still requires representative images, reviewed annotations, and measurements of accuracy, latency, and cost.

Traditional detection against Gemini spatial understanding across ten dimensions
Figure 3. Traditional detection against Gemini spatial understanding across ten dimensions. Entries are qualitative characterizations drawn from the text, not measurements; the article does not compare box quality on a shared dataset.

The comparison in Figure 3 is intended as a guide rather than a ranking. For high-volume, fixed-class, low-latency detection that needs tight boxes - for example, a camera inspecting the same parts continuously - a dedicated detector should be trained. For long-tail or changing classes, low-to-medium volume, fast time-to-value, or detection that requires reasoning, Gemini is the better fit.

Applications

The following scenarios, grouped by sector in Figure 4, share a common trait: the labeling step, not inference, was the bottleneck, and removing it changes feasibility.

Applications of prompt-defined detection by sector
Figure 4. Applications of prompt-defined detection by sector. Scenarios are illustrative; none is a measured deployment.

Limitations and Recommended Practice

Gemini's boxes are approximate, non-deterministic, billed per call, and take seconds rather than milliseconds. A design should account for these properties.

  • Approximate boxes. The output is suitable for cropping a region, checking whether a condition is present, or routing to a human. It is not suitable for sub-pixel measurement or safety-critical localization. Where high IoU is needed, a detector should be trained - optionally using Gemini to generate the labels.

  • Non-determinism. The request should set temperature=0, but small run-to-run variation should be expected. Evaluation (IoU, precision, recall on a held-out set) should be built into the pipeline rather than trusting a single response.

  • Latency and cost. Evaluate request volume, caching, and image resizing against the application’s requirements. Normalized boxes are mapped to the original image dimensions. Downscaling can still change predictions, especially for small or occluded objects.

  • Pre-GA status. The capability can change. It should be isolated behind an interface so that swapping models, or falling back to a trained detector, is a small change.

Four properties of Gemini boxes and the design response
Figure 5. Four properties of Gemini bounding boxes, what each implies for an application, and the design response the article recommends.

A common production pattern is hybrid: Gemini is used to explore the problem, to auto-label a dataset, and to handle the long tail, while a distilled or trained model serves the high-volume, fixed-class path. In this design, Gemini is the labeling engine and the fallback rather than the steady-state inference engine.

Hybrid production pattern
Figure 6. Hybrid production pattern. Gemini explores the problem, auto-labels a dataset, and handles the long tail as the fallback; a distilled or trained detector serves the high-volume, fixed-class path. Today's prompt produces tomorrow's training set.

Implementation: Prompt2Box

The earlier code sample is correct, but production use requires additional engineering: mapping normalized (y, x) coordinates to pixel (x, y), downscaling large images, retrying transient errors, surfacing safety blocks clearly, running images concurrently without sharing a non-thread-safe client, filtering low-quality predictions, reading structured output, supporting both Developer API and Vertex AI authentication, and measuring quality.

Prompt2Box is an open-source (MIT) Python library and CLI that packages these details. It uses the same recommended pattern - a response_schema of label and box_2d, read from response.parsed - and adds ergonomics. The following example runs the same shelf task end to end.

Prompt2Box also includes an evaluation harness that computes precision, recall, and mean IoU against ground truth, so that it can be measured whether the trade-offs above are acceptable for a given set of images before any commitment is made. Prompt2Box is independent open source and not a Google product; it is included here as a concrete example of the integration layer this capability invites.

Reference Architecture

A pragmatic production pipeline has five stages, shown in Figure 7:

  1. Pre-process: the image is downscaled (the longest edge is capped) and the original dimensions are kept for coordinate mapping.

  2. Detect: Gemini is called with a response_schema of label and box_2d, temperature=0, retry with backoff, and a request timeout.

  3. Post-process: the 0-1000 coordinates are converted to pixels, (y, x) is swapped to (x, y), and the results are refined to drop whole-frame and duplicate boxes.

  4. Consume: inspect detections before using them to crop, route, count, or label data. Route ambiguous, high-impact, or policy-flagged detections to human review. Prompt2Box does not expose a calibrated confidence score.

  5. Evaluate: IoU, precision, and recall are tracked on a held-out set, and model and prompt changes are gated on the results.

Stages 1, 3, and 5 are the layer Prompt2Box packages. Stage 4's auto-labeling path is the long-term strategy: the prompt in use today produces the training set used later.

Detection pipeline with Gemini
Figure 7. Detection pipeline with Gemini. Stage 4 (Consume) offers three paths that can be combined: direct use, human review of ambiguous or high-impact detections, and auto-labeling for a trained detector. Stages 1, 3 and 5 are the layer Prompt2Box packages.

Conclusion

Prompt-defined object detection reduces the data collection and training needed to explore new labels. Its practical value depends on the accuracy, latency, and cost requirements of the application.

Prompt2Box 0.1.0 is an independent open-source Python library and CLI for prompt-based object detection with Gemini. Evaluate it on representative images, record failure cases, and use a dedicated detector where precise or sustained high-volume detection is required.

Sources and version notes

Prompt2Box repository and documentation

Research

Browse all research, analyses, and software.

Browse all research notes and technical analyses.

Abstract

A pretrained Gemini model can return labeled bounding boxes for an image from a natural-language instruction, with no additional task-specific training dataset or detector fine-tuning, and no fixed class list. This article traces four phases of object detection, describes the response format (a label and a box_2d of four integers normalized to a 0-1000 grid in (y, x) order), and compares the approach with trained detectors across ten dimensions.

Trained detectors remain preferable for high-volume, fixed-class, low-latency detection that needs tight boxes. Prompt-defined detection suits long-tail or changing classes and the early validation of a use case. The article also introduces Prompt2Box, an open-source library that packages the integration details, and a five-stage reference pipeline. Gemini bounding box detection is a Pre-GA (experimental) feature.

Introduction

Computer vision teams have always paid an overhead to answer a simple question: where the objects in an image are. Historically, drawing a labeled box around each object meant collecting a dataset, writing annotation guidelines, training a model, standing up a serving stack, and committing in advance to a fixed list of classes. With multimodal models, that workflow is changing. An image and a natural-language instruction can now be sent to Gemini, which returns labeled bounding boxes - no additional task-specific training dataset or detector fine-tuning, and no fixed class list.

This article examines how object detection evolved to this point, how Gemini's bounding box detection (spatial understanding) works, where it fits relative to traditional computer vision, and how it can be put into production. It also introduces Prompt2Box, an open-source library that packages the integration details so that the capability can be adopted with a single import.

The cited documentation describes bounding-box detection as a Pre-GA capability. Structured output, evaluation gates, and hybrid pipelines can help manage errors. They do not establish suitability for a particular deployment.

Background: A Brief History of Object Detection

Object detection has always combined two tasks: localization (where an object is, expressed as a box) and classification (what the object is, expressed as a label). The way the field has solved those tasks has moved through four phases, summarized in Figure 1, and the common thread is that each phase moved more of the required prior knowledge from the engineer to the model.

Four phases of object detection
Figure 1. The four phases of object detection, from hand-crafted features to multimodal models.

Hand-Crafted Features (2001-2013)

Early detection relied on features that humans designed by hand. Viola-Jones (2001) made real-time face detection practical with Haar-like features and a cascade of weak classifiers. HOG with a linear SVM (2005) generalized the approach and underpinned a generation of pedestrian detectors. Deformable Part Models treated an object as a constellation of parts. In every case, a human decided what a feature was, and adding a new class meant new engineering.

Learned Features and CNN Detectors (2014-2019)

Deep learning replaced hand-designed features with features learned from labeled data. The R-CNN family (2014-2015) introduced two-stage detection: propose regions, then classify them. YOLO and SSD (2016) reframed detection as a single pass over a grid, trading some accuracy for speed - the lineage that still runs on edge devices and factory cameras today. RetinaNet (2017) addressed class imbalance, and Mask R-CNN extended boxes to pixel-level masks. These detectors are fast, cheap per inference, deterministic, and accurate, but they share one constraint: a closed vocabulary. A model can only detect the classes it was trained on, and a new class means relabeling and retraining.

Transformers and Open-Vocabulary Detection (2020-2023)

Two ideas removed the closed-vocabulary ceiling. DETR (2020) recast detection as set prediction with a transformer, removing anchors and post processing. Vision-language models then tied detection to natural language: CLIP (2021) aligned images and text in a shared embeddings space, and detectors such as GLIP, OWL-ViT, and Grounding DINO extended that alignment to the region level, so that a class could be detected by describing it rather than by training on it. (SAM added promptable segmentation in the same period, though it is prompted by points and boxes rather than language.) Detection moved from "choose from a fixed class list" to "ground this phrase in this image."

Detection with Multimodal Models (2023-Present)

Multimodal large language models, including Gemini, absorbed grounding into a general reasoning engine. The model already understands an image well enough to answer questions about it, so returning coordinates is one more output format. Because the interface is natural language, the class taxonomy is no longer a configuration decided up front - it is an instruction supplied at request time.

Method: Bounding Box Detection with Gemini

Gemini receives a prompt and one or more images or video frames. For each detected object, the model returns two fields:

  • The label field is a short string. The vocabulary is open, so a label can be "car" or "the rusty bicycle leaning on the left wall," depending on the instruction.

  • The box_2d field holds four integers, [y_min, x_min, y_max, x_max], normalized to a 0-1000 grid with the origin at the top-left corner.

Two details matter when this output is integrated, and they are summarized with the response format in Figure 2:

  • Coordinate order is (y, x), not (x, y). Most tooling (OpenCV, Pillow) expects (x_min, y_min, x_max, y_max). Gemini returns row-major (y, x), so the pairs must be swapped or the boxes will be transposed.

  • Coordinates are normalized to 0-1000, not pixels. Rescaling to a given image uses x_px = x_norm / 1000 * width. The same response maps onto a thumbnail or a full-resolution original, but the original dimensions are needed to draw boxes.

Gemini bounding box response format
Figure 2. The Gemini bounding box response format and the conversions required by most tooling.

A JSON response schema defines the expected labels and box fields, making responses easier to parse and validate. Schema conformance does not establish that a detection is correct. The following example uses the google-genai SDK for Python.

The response_schema parameter is what turns a model that usually returns JSON into an API that returns a typed list of bounding boxes.

Analysis: Practical Trade-offs

Prompt2Box provides a prompt-based route to object localization without task-specific detector training. This article does not compare its box quality with a trained detector on a shared reviewed dataset.

Taxonomy Defined at Request Time

Traditional detection forces an early, hard-to-reverse decision about which classes the model will know. With Gemini, the taxonomy is a string in the request. The same endpoint can detect "forklift" today and "spilled liquid on the warehouse floor" tomorrow, with no retraining or redeployment. For businesses whose objects of interest change with the season, the catalog, or a regulation, this is a significant simplification.

Detection by Instruction

A conventional detector recognizes "person." Gemini can detect "employees not wearing a hard hat," because it reasons over the scene rather than matching a single class. Conditions and relationships can be detected - an open drawer, damaged packaging, an expired sign - which moves detection from object presence toward situation understanding.

Cost Shifted from Up-Front to Per-Use

Prompt-based detection can support an initial prototype without task-specific detector training. Validating a use case still requires representative images, reviewed annotations, and measurements of accuracy, latency, and cost.

Traditional detection against Gemini spatial understanding across ten dimensions
Figure 3. Traditional detection against Gemini spatial understanding across ten dimensions. Entries are qualitative characterizations drawn from the text, not measurements; the article does not compare box quality on a shared dataset.

The comparison in Figure 3 is intended as a guide rather than a ranking. For high-volume, fixed-class, low-latency detection that needs tight boxes - for example, a camera inspecting the same parts continuously - a dedicated detector should be trained. For long-tail or changing classes, low-to-medium volume, fast time-to-value, or detection that requires reasoning, Gemini is the better fit.

Applications

The following scenarios, grouped by sector in Figure 4, share a common trait: the labeling step, not inference, was the bottleneck, and removing it changes feasibility.

Applications of prompt-defined detection by sector
Figure 4. Applications of prompt-defined detection by sector. Scenarios are illustrative; none is a measured deployment.

Limitations and Recommended Practice

Gemini's boxes are approximate, non-deterministic, billed per call, and take seconds rather than milliseconds. A design should account for these properties.

  • Approximate boxes. The output is suitable for cropping a region, checking whether a condition is present, or routing to a human. It is not suitable for sub-pixel measurement or safety-critical localization. Where high IoU is needed, a detector should be trained - optionally using Gemini to generate the labels.

  • Non-determinism. The request should set temperature=0, but small run-to-run variation should be expected. Evaluation (IoU, precision, recall on a held-out set) should be built into the pipeline rather than trusting a single response.

  • Latency and cost. Evaluate request volume, caching, and image resizing against the application’s requirements. Normalized boxes are mapped to the original image dimensions. Downscaling can still change predictions, especially for small or occluded objects.

  • Pre-GA status. The capability can change. It should be isolated behind an interface so that swapping models, or falling back to a trained detector, is a small change.

Four properties of Gemini boxes and the design response
Figure 5. Four properties of Gemini bounding boxes, what each implies for an application, and the design response the article recommends.

A common production pattern is hybrid: Gemini is used to explore the problem, to auto-label a dataset, and to handle the long tail, while a distilled or trained model serves the high-volume, fixed-class path. In this design, Gemini is the labeling engine and the fallback rather than the steady-state inference engine.

Hybrid production pattern
Figure 6. Hybrid production pattern. Gemini explores the problem, auto-labels a dataset, and handles the long tail as the fallback; a distilled or trained detector serves the high-volume, fixed-class path. Today's prompt produces tomorrow's training set.

Implementation: Prompt2Box

The earlier code sample is correct, but production use requires additional engineering: mapping normalized (y, x) coordinates to pixel (x, y), downscaling large images, retrying transient errors, surfacing safety blocks clearly, running images concurrently without sharing a non-thread-safe client, filtering low-quality predictions, reading structured output, supporting both Developer API and Vertex AI authentication, and measuring quality.

Prompt2Box is an open-source (MIT) Python library and CLI that packages these details. It uses the same recommended pattern - a response_schema of label and box_2d, read from response.parsed - and adds ergonomics. The following example runs the same shelf task end to end.

Prompt2Box also includes an evaluation harness that computes precision, recall, and mean IoU against ground truth, so that it can be measured whether the trade-offs above are acceptable for a given set of images before any commitment is made. Prompt2Box is independent open source and not a Google product; it is included here as a concrete example of the integration layer this capability invites.

Reference Architecture

A pragmatic production pipeline has five stages, shown in Figure 7:

  1. Pre-process: the image is downscaled (the longest edge is capped) and the original dimensions are kept for coordinate mapping.

  2. Detect: Gemini is called with a response_schema of label and box_2d, temperature=0, retry with backoff, and a request timeout.

  3. Post-process: the 0-1000 coordinates are converted to pixels, (y, x) is swapped to (x, y), and the results are refined to drop whole-frame and duplicate boxes.

  4. Consume: inspect detections before using them to crop, route, count, or label data. Route ambiguous, high-impact, or policy-flagged detections to human review. Prompt2Box does not expose a calibrated confidence score.

  5. Evaluate: IoU, precision, and recall are tracked on a held-out set, and model and prompt changes are gated on the results.

Stages 1, 3, and 5 are the layer Prompt2Box packages. Stage 4's auto-labeling path is the long-term strategy: the prompt in use today produces the training set used later.

Detection pipeline with Gemini
Figure 7. Detection pipeline with Gemini. Stage 4 (Consume) offers three paths that can be combined: direct use, human review of ambiguous or high-impact detections, and auto-labeling for a trained detector. Stages 1, 3 and 5 are the layer Prompt2Box packages.

Conclusion

Prompt-defined object detection reduces the data collection and training needed to explore new labels. Its practical value depends on the accuracy, latency, and cost requirements of the application.

Prompt2Box 0.1.0 is an independent open-source Python library and CLI for prompt-based object detection with Gemini. Evaluate it on representative images, record failure cases, and use a dedicated detector where precise or sustained high-volume detection is required.

Sources and version notes

Prompt2Box repository and documentation

Research

Browse all research notes and technical analyses.

  • //

    [#hebula]

    &

    [#research]

  • //

    [#hebula]

    &

    [#research]

  • //

    [#hebula]

    &

    [#research]

  • //

    [#hebula]

    &

    [#research]

Research and collaboration

Have a research question?

Tell us what you’d like to test.

  • //

    [#hebula]

    &

    [#research]

  • //

    [#hebula]

    &

    [#research]

  • //

    [#hebula]

    &

    [#research]

  • //

    [#hebula]

    &

    [#research]

  • //

    [#hebula]

    &

    [#research]

  • //

    [#hebula]

    &

    [#research]

  • //

    [#hebula]

    &

    [#research]

  • //

    [#hebula]

    &

    [#research]

  • //

    [#hebula]

    &

    [#research]

Research and collaboration

Have a research question?

Tell us what you’d like to test.

  • //

    [#hebula]

    &

    [#research]

  • //

    [#hebula]

    &

    [#research]

  • //

    [#hebula]

    &

    [#research]

  • //

    [#hebula]

    &

    [#research]

  • //

    [#hebula]

    &

    [#research]

  • //

    [#hebula]

    &

    [#research]

  • //

    [#hebula]

    &

    [#research]

  • //

    [#hebula]

    &

    [#research]

  • //

    [#hebula]

    &

    [#research]

Research and collaboration

Have a research question?

Tell us what you’d like to test.

  • //

    [#hebula]

    &

    [#research]

  • //

    [#hebula]

    &

    [#research]

  • //

    [#hebula]

    &

    [#research]

  • //

    [#hebula]

    &

    [#research]

  • //

    [#hebula]

    &

    [#research]