grounding_dino_base

Grounding DINO Base

Grounding DINO is an open-set object detection model that marries Transformer-based detector DINO with grounded pre-training, enabling zero-shot detection of arbitrary objects from text prompts (category names or referring expressions). Achieves 52.5 AP on COCO zero-shot transfer and 63.0 AP fine-tuned.

Apache-2.0
Zero-Shot Object Detection
PyTorch
Transformers
English
by @AIOZAI
•
6
•
0

Last updated: 25 days ago


AIOZ AI Node Adapter Python

Grounding DINO Base

Zero-Shot Object Detection — open-set detector that detects arbitrary objects from text prompts.

Summary

Introduction

The Grounding DINO model was proposed in Grounding DINO: Marrying DINO with Grounded Pre-Training for Open-Set Object Detection by Shilong Liu, Zhaoyang Zeng, Tianhe Ren, Feng Li, Hao Zhang, Jie Yang, Chunyuan Li, Jianwei Yang, Hang Su, Jun Zhu, and Lei Zhang. Grounding DINO extends the closed-set Transformer-based DINO detector by marrying it with grounded text pre-training, enabling open-set and zero-shot object detection of arbitrary categories or referring expressions without fine-tuning. The model achieves remarkable performance, including 52.5 AP on COCO zero-shot transfer.

This repository packages the model under the standard AIOZ AI Node convention: construct an InputObject, call my_ai_lib.run(input_obj), and receive an OutputObject. The workflow accepts a local image path or HTTP(S) image URL alongside a natural language prompt (lowercased object phrases separated by dots), runs grounded object detection using IDEA-Research/grounding-dino-base, and returns:

  • Detected bounding boxes in absolute pixel coordinates [xmin, ymin, xmax, ymax].
  • Associated category labels extracted from the text prompt.
  • Detection confidence scores corresponding to each box.
  • An annotated visualization PNG with rendered bounding boxes, labels, and score badges wrapped in an AIOZ FileObject.

Parameters

Input

  • input_image (image/string, required): Local path or HTTP(S) URL for a JPEG, PNG, WebP, or BMP image.
  • text (string, required): Text prompt containing object category names or referring expressions. Category names should be lowercased and separated by periods (e.g. car. person. tree.).
  • threshold (float, optional): Bounding box detection confidence threshold. The default is 0.25.
  • text_threshold (float, optional): Association score threshold between text tokens and detected regions. The default is 0.25.
  • device (string, optional): cpu, cuda, or gpu. The default is cuda; execution falls back to CPU when CUDA is unavailable.
  • model_storage_directory (string, optional): Parent directory containing zero_shot_object_detection. AIOZ supplies this value at runtime.

Output

  • boxes (list of lists of floats): Detected bounding boxes in [xmin, ymin, xmax, ymax] absolute pixel coordinates.
  • labels (list of strings): Predicted category label corresponding to each detected box.
  • scores (list of floats): Confidence scores corresponding to each detection.
  • output_image (image, optional): An annotated PNG image named annotated_image.png with rendered bounding boxes, labels, and confidence scores wrapped in an AIOZ FileObject.

Examples

input_imagetextthresholdtext_thresholdoutput_image
a cat. a dog.0.35 0.30

Detection Output Format

{
  "boxes": [
    [482.55, 352.67, 827.67, 663.19],
    [191.69, 341.44, 523.1, 731.83]
  ],
  "labels": ["a cat", "a dog"],
  "scores": [0.93, 0.86],
  "output_image": "annotated_image.png"
}

Usage for developers

Requirements

  • Python 3.10 or newer
  • Git LFS for the model checkpoint (model.safetensors)
  • CUDA-capable GPU is optional (CPU inference is fully supported)
git lfs pull
pip install -r requirements.txt

Run the demo

python demo.py assets/sample.png --text "a cat. a dog." --output annotated_image.png

Use CPU explicitly when needed:

python demo.py assets/sample.png --text "a cat. a dog." --device cpu

Adjust detection thresholds:

python demo.py assets/sample.png --text "a cat. a dog." --threshold 0.35 --text-threshold 0.30

Use the AIOZ entry point

import my_ai_lib
from aioz_ainode_adapter.schemas import InputObject

input_obj = InputObject(
    input_image="assets/sample.png",
    text="a cat. a dog.",
    threshold=0.25,
    text_threshold=0.25,
    device="cuda",
    model_storage_directory="models",
)
output_obj = my_ai_lib.run(input_obj)

print(f"Detected {len(output_obj.boxes)} objects:")
for box, label, score in zip(output_obj.boxes, output_obj.labels, output_obj.scores):
    print(f" - {label} ({score:.2f}): {box}")

if output_obj.output_image:
    print(f"Annotated visualization saved: {output_obj.output_image.name}")

The public API is my_ai_lib.run(input_obj). Task-specific schemas and inference logic live in my_ai_lib/run.py as MyInput, MyOutput, do_ai_task, and run.

Project structure

.
├── aioz_ainode_adapter/
├── assets/
│   └── sample.png
├── models/
│   └── zero_shot_object_detection/
│       ├── config.json
│       ├── model.safetensors
│       ├── preprocessor_config.json
│       ├── special_tokens_map.json
│       ├── tokenizer_config.json
│       ├── tokenizer.json
│       └── vocab.txt
├── my_ai_lib/
│   ├── __init__.py
│   └── run.py
├── demo.py
├── README.md
└── requirements.txt

References and attribution

License

The IDEA-Research/grounding-dino-base model and code are licensed under the Apache License 2.0. Please refer to the upstream repository for complete license terms.

Citation

@article{liu2023grounding,
  title={Grounding DINO: Marrying DINO with Grounded Pre-Training for Open-Set Object Detection},
  author={Liu, Shilong and Zeng, Zhaoyang and Ren, Tianhe and Li, Feng and Zhang, Hao and Yang, Jie and Li, Chunyuan and Yang, Jianwei and Su, Hang and Zhu, Jun and Zhang, Lei},
  journal={arXiv preprint arXiv:2303.05499},
  year={2023}
}