Instructions to use zeromodels/grounding_dino_tiny with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- KerasFormers
How to use zeromodels/grounding_dino_tiny with KerasFormers:
# No code snippets available yet for this library. # To use this model, check the repository files and the library's documentation. # Want to help? PRs adding snippets are welcome at: # https://github.com/huggingface/huggingface.js
- Keras
How to use zeromodels/grounding_dino_tiny with Keras:
# Available backend options are: "jax", "torch", "tensorflow". import os os.environ["KERAS_BACKEND"] = "jax" import keras model = keras.saving.load_model("hf://zeromodels/grounding_dino_tiny") - Notebooks
- Google Colab
- Kaggle
Run Grounding DINO with Keras 3: JAX, PyTorch, or TensorFlow
kerasformers/grounding_dino_tiny
Paper: Grounding DINO: Marrying DINO with Grounded Pre-Training for Open-Set Object Detection (arXiv:2303.05499) · HF Papers
Grounding DINO performs open-set, text-grounded object detection: it finds the objects a free-form text prompt names, not a fixed label set. A Swin image backbone and a BERT text encoder feed a deformable cross-modality encoder that fuses vision and language, a contrastive query-selection stage picks object proposals, and a decoder with iterative box refinement emits one box per query scored against the prompt tokens. No anchors, no NMS, and categories that were never in a detection training set (here "Swin-Tiny" backbone).
For more details on the model, please go to IDEA-Research's original model card.
Pure-Keras 3 conversion of IDEA-Research/grounding-dino-tiny for kerasformers. One implementation runs unmodified on TensorFlow / Torch / JAX.
This is an open-set object detection checkpoint (GroundingDinoForObjectDetection, Swin-Tiny backbone): each query predicts a box and a score over the prompt tokens.
✨ Quick start
import os
os.environ["KERAS_BACKEND"] = "torch" # or "jax" / "tensorflow"
import torch
from PIL import Image
from kerasformers.models.grounding_dino import (
GroundingDinoForObjectDetection,
GroundingDinoProcessor,
)
model = GroundingDinoForObjectDetection.from_weights("kerasformers/grounding_dino_tiny")
processor = GroundingDinoProcessor.from_weights("kerasformers/grounding_dino_tiny")
image = Image.open("your_image.jpg").convert("RGB")
# Prompts are free text; pass a list of candidates (or one "a. b. c." string). Skip
# articles: in "a paddle" the "a" can outscore the noun.
inputs = processor(images=image, text=["person", "paddle", "board"])
with torch.no_grad(): # torch backend: avoids a large autograd graph (can OOM otherwise)
output = model(inputs)
# output["logits"]: (1, 900, 256)
# output["pred_boxes"]: (1, 900, 4)
results = processor.post_process_object_detection(
output,
threshold=0.3,
target_sizes=[(image.height, image.width)],
input_ids=inputs["input_ids"],
)[0]
for score, name, box in sorted(
zip(results["scores"], results["text_labels"], results["boxes"]),
key=lambda d: -float(d[0]),
):
print(f"{name}: {float(score):.3f} {[round(float(v)) for v in box]}")
Load either Grounding DINO variant the same way with from_weights("kerasformers/<variant>"):
| Variant | Hub | Backbone |
|---|---|---|
grounding_dino_tiny |
kerasformers/grounding_dino_tiny |
Swin-Tiny |
grounding_dino_base |
kerasformers/grounding_dino_base |
Swin-Base |
Tips
- Set
KERAS_BACKENDbefore importing Keras / kerasformers. - On the torch backend, wrap inference in
with torch.no_grad():— the forward keeps a large autograd graph otherwise and can OOM. The JAX / TensorFlow backends need no such wrap. - Write prompts as lower-case phrases separated as a list or by
.; drop articles ("a", "the") so the noun scores highest.post_process_object_detectionneedsinput_ids=to map scores back to prompt words (text_labels). threshold=0.3is a reasonable start; raise it for cleaner scenes.- See Grounding DINO docs and Loading Weights.
- Community / upstream safetensors still work via the
hf:prefix, e.g.GroundingDinoForObjectDetection.from_weights("hf:IDEA-Research/grounding-dino-tiny").
Special Thanks
A huge thank you to the IDEA-Research authors for creating and releasing Grounding DINO.
License: Apache 2.0.
- Downloads last month
- 855
Model tree for zeromodels/grounding_dino_tiny
Base model
IDEA-Research/grounding-dino-tiny