IMvision12 commited on
Commit
bfa43c7
·
verified ·
1 Parent(s): 28a6852

Migrate to zeromodels (rename kf_*.json -> zm_*.json, fix refs in config + README, ensure tag + badge)

Browse files
README.md CHANGED
@@ -1,92 +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
- [![GitHub](https://img.shields.io/badge/GitHub-KerasFormers-black?logo=github)](https://github.com/IMvision12/KerasFormers) [![Docs](https://img.shields.io/badge/Docs-Grounding%20DINO-blue)](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.
 
1
+ ---
2
+ pipeline_tag: zero-shot-object-detection
3
+ license: apache-2.0
4
+ base_model: IDEA-Research/grounding-dino-base
5
+ library_name: zeromodels
6
+ tags:
7
+ - keras
8
+ - zeromodels
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
+ [![GitHub](https://img.shields.io/badge/GitHub-ZeroModels-black?logo=github)](https://github.com/IMvision12/ZeroModels) [![Docs](https://img.shields.io/badge/Docs-Grounding%20DINO-blue)](https://imvision12.github.io/ZeroModels/grounding_dino/)
20
+
21
+ # zeromodels/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 [zeromodels](https://github.com/IMvision12/ZeroModels). 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 zeromodels.models.grounding_dino import (
42
+ GroundingDinoForObjectDetection,
43
+ GroundingDinoProcessor,
44
+ )
45
+
46
+ model = GroundingDinoForObjectDetection.from_weights("zeromodels/grounding_dino_base")
47
+ processor = GroundingDinoProcessor.from_weights("zeromodels/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("zeromodels/<variant>")`:
73
+
74
+ | Variant | Hub | Backbone |
75
+ |---|---|---|
76
+ | `grounding_dino_tiny` | [`zeromodels/grounding_dino_tiny`](https://huggingface.co/zeromodels/grounding_dino_tiny) | Swin-Tiny |
77
+ | `grounding_dino_base` | [`zeromodels/grounding_dino_base`](https://huggingface.co/zeromodels/grounding_dino_base) | Swin-Base |
78
+
79
+ ## Tips
80
+
81
+ - Set `KERAS_BACKEND` **before** importing Keras / zeromodels.
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/ZeroModels/grounding_dino/) and [Loading Weights](https://imvision12.github.io/ZeroModels/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 → zm_config.json RENAMED
@@ -1,56 +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
  }
 
1
+ {
2
+ "library_name": "zeromodels",
3
+ "zeromodels_version": "1.2.1",
4
+ "model_module": "zeromodels.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 → zm_preprocessor.json RENAMED
@@ -1,20 +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
  }
 
1
+ {
2
+ "library_name": "zeromodels",
3
+ "zeromodels_version": "1.1.3",
4
+ "preprocessor_module": "zeromodels.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
  }