Instructions to use zeromodels/grounding_dino_base with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- KerasFormers
How to use zeromodels/grounding_dino_base 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_base 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_base") - Notebooks
- Google Colab
- Kaggle
Commit ·
28a6852
0
Parent(s):
Super-squash branch 'main' using huggingface_hub
Browse files- .gitattributes +35 -0
- README.md +92 -0
- kf_config.json +56 -0
- kf_preprocessor.json +20 -0
- model.weights.h5 +3 -0
- tokenizer.json +0 -0
.gitattributes
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
| 2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
| 3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
| 4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
| 5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
| 6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
| 7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
| 8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
| 9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
| 10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
| 11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
| 12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
| 13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
| 14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
| 15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
| 16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
| 17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
| 18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
| 19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
| 20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
| 21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
| 22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
| 23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
| 24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
| 25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
| 26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
| 27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
| 28 |
+
*.tar filter=lfs diff=lfs merge=lfs -text
|
| 29 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
| 30 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
| 31 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
| 32 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
| 33 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
pipeline_tag: zero-shot-object-detection
|
| 3 |
+
license: apache-2.0
|
| 4 |
+
base_model: IDEA-Research/grounding-dino-base
|
| 5 |
+
library_name: kerasformers
|
| 6 |
+
tags:
|
| 7 |
+
- keras
|
| 8 |
+
- kerasformers
|
| 9 |
+
- grounding-dino
|
| 10 |
+
- zero-shot-object-detection
|
| 11 |
+
- arxiv:2303.05499
|
| 12 |
+
- pytorch
|
| 13 |
+
- jax
|
| 14 |
+
- tf
|
| 15 |
+
---
|
| 16 |
+
|
| 17 |
+
# Run Grounding DINO with Keras 3: JAX, PyTorch, or TensorFlow
|
| 18 |
+
|
| 19 |
+
[](https://github.com/IMvision12/KerasFormers) [](https://imvision12.github.io/KerasFormers/grounding_dino/)
|
| 20 |
+
|
| 21 |
+
# kerasformers/grounding_dino_base
|
| 22 |
+
|
| 23 |
+
Paper: [Grounding DINO: Marrying DINO with Grounded Pre-Training for Open-Set Object Detection (arXiv:2303.05499)](https://arxiv.org/abs/2303.05499) · [HF Papers](https://huggingface.co/papers/2303.05499)
|
| 24 |
+
|
| 25 |
+
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-Base" backbone).
|
| 26 |
+
|
| 27 |
+
For more details on the model, please go to IDEA-Research's original [model card](https://huggingface.co/IDEA-Research/grounding-dino-base).
|
| 28 |
+
|
| 29 |
+
Pure-**Keras 3** conversion of [`IDEA-Research/grounding-dino-base`](https://huggingface.co/IDEA-Research/grounding-dino-base) for [kerasformers](https://github.com/IMvision12/KerasFormers). One implementation runs unmodified on **TensorFlow / Torch / JAX**.
|
| 30 |
+
|
| 31 |
+
This is an **open-set object detection** checkpoint (`GroundingDinoForObjectDetection`, Swin-Base backbone): each query predicts a box and a score over the prompt tokens.
|
| 32 |
+
|
| 33 |
+
## ✨ Quick start
|
| 34 |
+
|
| 35 |
+
```python
|
| 36 |
+
import os
|
| 37 |
+
os.environ["KERAS_BACKEND"] = "torch" # or "jax" / "tensorflow"
|
| 38 |
+
|
| 39 |
+
import torch
|
| 40 |
+
from PIL import Image
|
| 41 |
+
from kerasformers.models.grounding_dino import (
|
| 42 |
+
GroundingDinoForObjectDetection,
|
| 43 |
+
GroundingDinoProcessor,
|
| 44 |
+
)
|
| 45 |
+
|
| 46 |
+
model = GroundingDinoForObjectDetection.from_weights("kerasformers/grounding_dino_base")
|
| 47 |
+
processor = GroundingDinoProcessor.from_weights("kerasformers/grounding_dino_base")
|
| 48 |
+
|
| 49 |
+
image = Image.open("your_image.jpg").convert("RGB")
|
| 50 |
+
# Prompts are free text; pass a list of candidates (or one "a. b. c." string). Skip
|
| 51 |
+
# articles: in "a paddle" the "a" can outscore the noun.
|
| 52 |
+
inputs = processor(images=image, text=["person", "paddle", "board"])
|
| 53 |
+
|
| 54 |
+
with torch.no_grad(): # torch backend: avoids a large autograd graph (can OOM otherwise)
|
| 55 |
+
output = model(inputs)
|
| 56 |
+
# output["logits"]: (1, 900, 256)
|
| 57 |
+
# output["pred_boxes"]: (1, 900, 4)
|
| 58 |
+
|
| 59 |
+
results = processor.post_process_object_detection(
|
| 60 |
+
output,
|
| 61 |
+
threshold=0.3,
|
| 62 |
+
target_sizes=[(image.height, image.width)],
|
| 63 |
+
input_ids=inputs["input_ids"],
|
| 64 |
+
)[0]
|
| 65 |
+
for score, name, box in sorted(
|
| 66 |
+
zip(results["scores"], results["text_labels"], results["boxes"]),
|
| 67 |
+
key=lambda d: -float(d[0]),
|
| 68 |
+
):
|
| 69 |
+
print(f"{name}: {float(score):.3f} {[round(float(v)) for v in box]}")
|
| 70 |
+
```
|
| 71 |
+
|
| 72 |
+
Load either Grounding DINO variant the same way with `from_weights("kerasformers/<variant>")`:
|
| 73 |
+
|
| 74 |
+
| Variant | Hub | Backbone |
|
| 75 |
+
|---|---|---|
|
| 76 |
+
| `grounding_dino_tiny` | [`kerasformers/grounding_dino_tiny`](https://huggingface.co/kerasformers/grounding_dino_tiny) | Swin-Tiny |
|
| 77 |
+
| `grounding_dino_base` | [`kerasformers/grounding_dino_base`](https://huggingface.co/kerasformers/grounding_dino_base) | Swin-Base |
|
| 78 |
+
|
| 79 |
+
## Tips
|
| 80 |
+
|
| 81 |
+
- Set `KERAS_BACKEND` **before** importing Keras / kerasformers.
|
| 82 |
+
- 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.
|
| 83 |
+
- Write prompts as lower-case phrases separated as a list or by `.`; **drop articles** ("a", "the") so the noun scores highest. `post_process_object_detection` needs `input_ids=` to map scores back to prompt words (`text_labels`).
|
| 84 |
+
- `threshold=0.3` is a reasonable start; raise it for cleaner scenes.
|
| 85 |
+
- See [Grounding DINO docs](https://imvision12.github.io/KerasFormers/grounding_dino/) and [Loading Weights](https://imvision12.github.io/KerasFormers/loading_weights/).
|
| 86 |
+
- Community / upstream safetensors still work via the `hf:` prefix, e.g. `GroundingDinoForObjectDetection.from_weights("hf:IDEA-Research/grounding-dino-base")`.
|
| 87 |
+
|
| 88 |
+
## Special Thanks
|
| 89 |
+
|
| 90 |
+
A huge thank you to the IDEA-Research authors for creating and releasing Grounding DINO.
|
| 91 |
+
|
| 92 |
+
License: Apache 2.0.
|
kf_config.json
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"library_name": "kerasformers",
|
| 3 |
+
"kerasformers_version": "1.2.1",
|
| 4 |
+
"model_module": "kerasformers.models.grounding_dino",
|
| 5 |
+
"model_class": "GroundingDinoDetect",
|
| 6 |
+
"variant": "grounding_dino_base",
|
| 7 |
+
"weights": "model.weights.h5",
|
| 8 |
+
"schema_version": 2,
|
| 9 |
+
"weight_dtype": "float32",
|
| 10 |
+
"model_type": "grounding-dino",
|
| 11 |
+
"vision_config": {
|
| 12 |
+
"d_model": 256,
|
| 13 |
+
"encoder_layers": 6,
|
| 14 |
+
"encoder_ffn_dim": 2048,
|
| 15 |
+
"encoder_attention_heads": 8,
|
| 16 |
+
"decoder_layers": 6,
|
| 17 |
+
"decoder_ffn_dim": 2048,
|
| 18 |
+
"decoder_attention_heads": 8,
|
| 19 |
+
"num_queries": 900,
|
| 20 |
+
"num_feature_levels": 4,
|
| 21 |
+
"encoder_n_points": 4,
|
| 22 |
+
"decoder_n_points": 4,
|
| 23 |
+
"max_text_len": 256,
|
| 24 |
+
"query_dim": 4,
|
| 25 |
+
"two_stage": true,
|
| 26 |
+
"positional_embedding_temperature": 20.0,
|
| 27 |
+
"layer_norm_eps": 1e-05,
|
| 28 |
+
"activation_function": "relu",
|
| 29 |
+
"backbone_embed_dim": 128,
|
| 30 |
+
"backbone_depths": [
|
| 31 |
+
2,
|
| 32 |
+
2,
|
| 33 |
+
18,
|
| 34 |
+
2
|
| 35 |
+
],
|
| 36 |
+
"backbone_num_heads": [
|
| 37 |
+
4,
|
| 38 |
+
8,
|
| 39 |
+
16,
|
| 40 |
+
32
|
| 41 |
+
],
|
| 42 |
+
"backbone_window_size": 12,
|
| 43 |
+
"backbone_out_indices": [
|
| 44 |
+
2,
|
| 45 |
+
3,
|
| 46 |
+
4
|
| 47 |
+
],
|
| 48 |
+
"text_vocab_size": 30522,
|
| 49 |
+
"text_hidden_size": 768,
|
| 50 |
+
"text_num_layers": 12,
|
| 51 |
+
"text_num_heads": 12,
|
| 52 |
+
"text_intermediate_size": 3072,
|
| 53 |
+
"text_max_position_embeddings": 512,
|
| 54 |
+
"text_layer_norm_eps": 1e-12
|
| 55 |
+
}
|
| 56 |
+
}
|
kf_preprocessor.json
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"library_name": "kerasformers",
|
| 3 |
+
"kerasformers_version": "1.1.3",
|
| 4 |
+
"preprocessor_module": "kerasformers.models.grounding_dino",
|
| 5 |
+
"preprocessor_class": "GroundingDinoImageProcessor",
|
| 6 |
+
"variant": "grounding_dino_base",
|
| 7 |
+
"shortest_edge": 800,
|
| 8 |
+
"longest_edge": 1333,
|
| 9 |
+
"image_mean": [
|
| 10 |
+
0.48500001430511475,
|
| 11 |
+
0.4560000002384186,
|
| 12 |
+
0.4059999883174896
|
| 13 |
+
],
|
| 14 |
+
"image_std": [
|
| 15 |
+
0.2290000021457672,
|
| 16 |
+
0.2240000069141388,
|
| 17 |
+
0.22499999403953552
|
| 18 |
+
],
|
| 19 |
+
"data_format": null
|
| 20 |
+
}
|
model.weights.h5
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:61fa7f3119e66f7d621c096e4b39a8f3258ccf375c9e06f11f4a1cee379c7e14
|
| 3 |
+
size 933880784
|
tokenizer.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|