Zero-Shot Object Detection
ZeroModels
Keras
PyTorch
JAX
TensorFlow
owlv2
open-vocabulary
object-detection
Instructions to use zeromodels/owlv2-base-patch16 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- ZeroModels
How to use zeromodels/owlv2-base-patch16 with ZeroModels:
# pip install -U zeromodels # ZeroModels is pure Keras 3, so pick a backend: "jax", "torch" or "tensorflow". import os os.environ["KERAS_BACKEND"] = "jax" from zeromodels import AutoZModel # AutoZModel reads the repo's model_type and loads the matching class. # For a task head use the matching loader, e.g. AutoZMImageClassify / AutoZMDetect / # AutoZMSemanticSegment / AutoZMTextGenerate (see zeromodels.auto). model = AutoZModel.from_weights("zeromodels/owlv2-base-patch16") - Keras
How to use zeromodels/owlv2-base-patch16 with Keras:
# !pip install -U keras tensorflow huggingface_hub # Keras needs TensorFlow installed to read "hf://" paths, so the tensorflow backend is selected here; # "jax" and "torch" also work for computation once TensorFlow is installed. import os os.environ["KERAS_BACKEND"] = "tensorflow" import keras model = keras.saving.load_model("hf://zeromodels/owlv2-base-patch16") - Notebooks
- Google Colab
- Kaggle
Migrate to zeromodels (rename kf_*.json -> zm_*.json, fix refs in config + README, ensure tag + badge)
Browse files- README.md +22 -22
- kf_config.json → zm_config.json +28 -28
- kf_preprocessor.json → zm_preprocessor.json +27 -27
README.md
CHANGED
|
@@ -2,10 +2,10 @@
|
|
| 2 |
pipeline_tag: zero-shot-object-detection
|
| 3 |
license: apache-2.0
|
| 4 |
base_model: google/owlv2-base-patch16
|
| 5 |
-
library_name:
|
| 6 |
tags:
|
| 7 |
- keras
|
| 8 |
-
-
|
| 9 |
- owlv2
|
| 10 |
- open-vocabulary
|
| 11 |
- zero-shot-object-detection
|
|
@@ -16,13 +16,13 @@ tags:
|
|
| 16 |
- tf
|
| 17 |
---
|
| 18 |
|
| 19 |
-
## ***See [our collection](https://huggingface.co/collections/
|
| 20 |
|
| 21 |
# Run OWLv2 with Keras 3: JAX, PyTorch, or TensorFlow
|
| 22 |
|
| 23 |
-
[](https://arxiv.org/abs/2306.09683) · [HF Papers](https://huggingface.co/papers/2306.09683)
|
| 28 |
|
|
@@ -30,7 +30,7 @@ OWLv2 keeps OWL-ViT's dual-tower skeleton and per-patch detection head, and scal
|
|
| 30 |
|
| 31 |
For more details on the model, please go to Google's original [model card](https://huggingface.co/google/owlv2-base-patch16).
|
| 32 |
|
| 33 |
-
Pure-**Keras 3** conversion of [`google/owlv2-base-patch16`](https://huggingface.co/google/owlv2-base-patch16) for [
|
| 34 |
|
| 35 |
This is an **open-vocabulary object detection** checkpoint (`Owlv2Detect`): pass free-text prompts at inference time.
|
| 36 |
|
|
@@ -41,15 +41,15 @@ import os
|
|
| 41 |
os.environ["KERAS_BACKEND"] = "torch" # or "jax" / "tensorflow"
|
| 42 |
|
| 43 |
from PIL import Image
|
| 44 |
-
from
|
| 45 |
Owlv2Detect,
|
| 46 |
Owlv2Processor,
|
| 47 |
Owlv2ImageProcessor,
|
| 48 |
)
|
| 49 |
|
| 50 |
-
model = Owlv2Detect.from_weights("
|
| 51 |
-
processor = Owlv2Processor.from_weights("
|
| 52 |
-
image_processor = Owlv2ImageProcessor.from_weights("
|
| 53 |
|
| 54 |
image = Image.open("your_image.jpg").convert("RGB")
|
| 55 |
prompts = ["a photo of a mug", "a photo of a knife"]
|
|
@@ -72,27 +72,27 @@ for score, name, box in zip(
|
|
| 72 |
print(f"{name}: {float(score):.3f} {box}")
|
| 73 |
```
|
| 74 |
|
| 75 |
-
Load any OWL-ViT / OWLv2 variant the same way with `from_weights("
|
| 76 |
|
| 77 |
| Variant | Hub | Family |
|
| 78 |
|---|---|---|
|
| 79 |
-
| `owlvit-base-patch32` | [`
|
| 80 |
-
| `owlvit-base-patch16` | [`
|
| 81 |
-
| `owlvit-large-patch14` | [`
|
| 82 |
-
| `owlv2-base-patch16` | [`
|
| 83 |
-
| `owlv2-base-patch16-ensemble` | [`
|
| 84 |
-
| `owlv2-base-patch16-finetuned` | [`
|
| 85 |
-
| `owlv2-large-patch14` | [`
|
| 86 |
-
| `owlv2-large-patch14-ensemble` | [`
|
| 87 |
-
| `owlv2-large-patch14-finetuned` | [`
|
| 88 |
|
| 89 |
## Tips
|
| 90 |
|
| 91 |
-
- Set `KERAS_BACKEND` **before** importing Keras /
|
| 92 |
- Prefer `Processor.from_weights(...)` so image size matches the variant.
|
| 93 |
- Open-vocab thresholds are often much lower than closed-set detectors (try `0.1`).
|
| 94 |
- OWLv2 pads to square before resize; pass the original `(height, width)` as `target_sizes` carefully (see the OWLv2 docs for the padding trap).
|
| 95 |
-
- See [OWLv2 docs](https://imvision12.github.io/
|
| 96 |
- Community / upstream safetensors still work via the `hf:` prefix, e.g. `Owlv2Detect.from_weights("hf:google/owlv2-base-patch16")`.
|
| 97 |
|
| 98 |
## Special Thanks
|
|
|
|
| 2 |
pipeline_tag: zero-shot-object-detection
|
| 3 |
license: apache-2.0
|
| 4 |
base_model: google/owlv2-base-patch16
|
| 5 |
+
library_name: zeromodels
|
| 6 |
tags:
|
| 7 |
- keras
|
| 8 |
+
- zeromodels
|
| 9 |
- owlv2
|
| 10 |
- open-vocabulary
|
| 11 |
- zero-shot-object-detection
|
|
|
|
| 16 |
- tf
|
| 17 |
---
|
| 18 |
|
| 19 |
+
## ***See [our collection](https://huggingface.co/collections/zeromodels/owlv2-6a6a7aaaf7cd6616646d8318) for all versions of OWLv2.***
|
| 20 |
|
| 21 |
# Run OWLv2 with Keras 3: JAX, PyTorch, or TensorFlow
|
| 22 |
|
| 23 |
+
[](https://github.com/IMvision12/ZeroModels) [](https://imvision12.github.io/ZeroModels/owlv2/) [](https://huggingface.co/collections/zeromodels/owlv2-6a6a7aaaf7cd6616646d8318)
|
| 24 |
|
| 25 |
+
# zeromodels/owlv2-base-patch16
|
| 26 |
|
| 27 |
Paper: [Scaling Open-Vocabulary Object Detection (arXiv:2306.09683)](https://arxiv.org/abs/2306.09683) · [HF Papers](https://huggingface.co/papers/2306.09683)
|
| 28 |
|
|
|
|
| 30 |
|
| 31 |
For more details on the model, please go to Google's original [model card](https://huggingface.co/google/owlv2-base-patch16).
|
| 32 |
|
| 33 |
+
Pure-**Keras 3** conversion of [`google/owlv2-base-patch16`](https://huggingface.co/google/owlv2-base-patch16) for [zeromodels](https://github.com/IMvision12/ZeroModels). One implementation runs unmodified on **TensorFlow / Torch / JAX**.
|
| 34 |
|
| 35 |
This is an **open-vocabulary object detection** checkpoint (`Owlv2Detect`): pass free-text prompts at inference time.
|
| 36 |
|
|
|
|
| 41 |
os.environ["KERAS_BACKEND"] = "torch" # or "jax" / "tensorflow"
|
| 42 |
|
| 43 |
from PIL import Image
|
| 44 |
+
from zeromodels.models.owlv2 import (
|
| 45 |
Owlv2Detect,
|
| 46 |
Owlv2Processor,
|
| 47 |
Owlv2ImageProcessor,
|
| 48 |
)
|
| 49 |
|
| 50 |
+
model = Owlv2Detect.from_weights("zeromodels/owlv2-base-patch16")
|
| 51 |
+
processor = Owlv2Processor.from_weights("zeromodels/owlv2-base-patch16")
|
| 52 |
+
image_processor = Owlv2ImageProcessor.from_weights("zeromodels/owlv2-base-patch16")
|
| 53 |
|
| 54 |
image = Image.open("your_image.jpg").convert("RGB")
|
| 55 |
prompts = ["a photo of a mug", "a photo of a knife"]
|
|
|
|
| 72 |
print(f"{name}: {float(score):.3f} {box}")
|
| 73 |
```
|
| 74 |
|
| 75 |
+
Load any OWL-ViT / OWLv2 variant the same way with `from_weights("zeromodels/<variant>")` (use `Owlv2Detect` for this repo):
|
| 76 |
|
| 77 |
| Variant | Hub | Family |
|
| 78 |
|---|---|---|
|
| 79 |
+
| `owlvit-base-patch32` | [`zeromodels/owlvit-base-patch32`](https://huggingface.co/zeromodels/owlvit-base-patch32) | OWL-ViT |
|
| 80 |
+
| `owlvit-base-patch16` | [`zeromodels/owlvit-base-patch16`](https://huggingface.co/zeromodels/owlvit-base-patch16) | OWL-ViT |
|
| 81 |
+
| `owlvit-large-patch14` | [`zeromodels/owlvit-large-patch14`](https://huggingface.co/zeromodels/owlvit-large-patch14) | OWL-ViT |
|
| 82 |
+
| `owlv2-base-patch16` | [`zeromodels/owlv2-base-patch16`](https://huggingface.co/zeromodels/owlv2-base-patch16) | OWLv2 |
|
| 83 |
+
| `owlv2-base-patch16-ensemble` | [`zeromodels/owlv2-base-patch16-ensemble`](https://huggingface.co/zeromodels/owlv2-base-patch16-ensemble) | OWLv2 |
|
| 84 |
+
| `owlv2-base-patch16-finetuned` | [`zeromodels/owlv2-base-patch16-finetuned`](https://huggingface.co/zeromodels/owlv2-base-patch16-finetuned) | OWLv2 |
|
| 85 |
+
| `owlv2-large-patch14` | [`zeromodels/owlv2-large-patch14`](https://huggingface.co/zeromodels/owlv2-large-patch14) | OWLv2 |
|
| 86 |
+
| `owlv2-large-patch14-ensemble` | [`zeromodels/owlv2-large-patch14-ensemble`](https://huggingface.co/zeromodels/owlv2-large-patch14-ensemble) | OWLv2 |
|
| 87 |
+
| `owlv2-large-patch14-finetuned` | [`zeromodels/owlv2-large-patch14-finetuned`](https://huggingface.co/zeromodels/owlv2-large-patch14-finetuned) | OWLv2 |
|
| 88 |
|
| 89 |
## Tips
|
| 90 |
|
| 91 |
+
- Set `KERAS_BACKEND` **before** importing Keras / zeromodels.
|
| 92 |
- Prefer `Processor.from_weights(...)` so image size matches the variant.
|
| 93 |
- Open-vocab thresholds are often much lower than closed-set detectors (try `0.1`).
|
| 94 |
- OWLv2 pads to square before resize; pass the original `(height, width)` as `target_sizes` carefully (see the OWLv2 docs for the padding trap).
|
| 95 |
+
- See [OWLv2 docs](https://imvision12.github.io/ZeroModels/owlv2/) and [Loading Weights](https://imvision12.github.io/ZeroModels/loading_weights/).
|
| 96 |
- Community / upstream safetensors still work via the `hf:` prefix, e.g. `Owlv2Detect.from_weights("hf:google/owlv2-base-patch16")`.
|
| 97 |
|
| 98 |
## Special Thanks
|
kf_config.json → zm_config.json
RENAMED
|
@@ -1,29 +1,29 @@
|
|
| 1 |
-
{
|
| 2 |
-
"library_name": "
|
| 3 |
-
"
|
| 4 |
-
"model_module": "
|
| 5 |
-
"model_class": "Owlv2Detect",
|
| 6 |
-
"variant": "owlv2-base-patch16",
|
| 7 |
-
"weights": "model.weights.h5",
|
| 8 |
-
"schema_version": 2,
|
| 9 |
-
"weight_dtype": "float32",
|
| 10 |
-
"model_type": "owlv2",
|
| 11 |
-
"text_config": {
|
| 12 |
-
"hidden_dim": 512,
|
| 13 |
-
"intermediate_size": 2048,
|
| 14 |
-
"num_heads": 8,
|
| 15 |
-
"num_layers": 12,
|
| 16 |
-
"max_position_embeddings": 16,
|
| 17 |
-
"vocab_size": 49408
|
| 18 |
-
},
|
| 19 |
-
"vision_config": {
|
| 20 |
-
"image_size": 960,
|
| 21 |
-
"patch_size": 16,
|
| 22 |
-
"hidden_dim": 768,
|
| 23 |
-
"intermediate_size": 3072,
|
| 24 |
-
"num_layers": 12,
|
| 25 |
-
"num_heads": 12
|
| 26 |
-
},
|
| 27 |
-
"projection_dim": 512,
|
| 28 |
-
"image_size": null
|
| 29 |
}
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"library_name": "zeromodels",
|
| 3 |
+
"zeromodels_version": "1.2.1",
|
| 4 |
+
"model_module": "zeromodels.models.owlv2",
|
| 5 |
+
"model_class": "Owlv2Detect",
|
| 6 |
+
"variant": "owlv2-base-patch16",
|
| 7 |
+
"weights": "model.weights.h5",
|
| 8 |
+
"schema_version": 2,
|
| 9 |
+
"weight_dtype": "float32",
|
| 10 |
+
"model_type": "owlv2",
|
| 11 |
+
"text_config": {
|
| 12 |
+
"hidden_dim": 512,
|
| 13 |
+
"intermediate_size": 2048,
|
| 14 |
+
"num_heads": 8,
|
| 15 |
+
"num_layers": 12,
|
| 16 |
+
"max_position_embeddings": 16,
|
| 17 |
+
"vocab_size": 49408
|
| 18 |
+
},
|
| 19 |
+
"vision_config": {
|
| 20 |
+
"image_size": 960,
|
| 21 |
+
"patch_size": 16,
|
| 22 |
+
"hidden_dim": 768,
|
| 23 |
+
"intermediate_size": 3072,
|
| 24 |
+
"num_layers": 12,
|
| 25 |
+
"num_heads": 12
|
| 26 |
+
},
|
| 27 |
+
"projection_dim": 512,
|
| 28 |
+
"image_size": null
|
| 29 |
}
|
kf_preprocessor.json → zm_preprocessor.json
RENAMED
|
@@ -1,28 +1,28 @@
|
|
| 1 |
-
{
|
| 2 |
-
"library_name": "
|
| 3 |
-
"
|
| 4 |
-
"preprocessor_module": "
|
| 5 |
-
"preprocessor_class": "Owlv2ImageProcessor",
|
| 6 |
-
"variant": "owlv2-base-patch16",
|
| 7 |
-
"size": {
|
| 8 |
-
"height": 960,
|
| 9 |
-
"width": 960
|
| 10 |
-
},
|
| 11 |
-
"resample": "bicubic",
|
| 12 |
-
"do_rescale": true,
|
| 13 |
-
"rescale_factor": 0.00392156862745098,
|
| 14 |
-
"do_pad": true,
|
| 15 |
-
"do_normalize": true,
|
| 16 |
-
"image_mean": [
|
| 17 |
-
0.48145466,
|
| 18 |
-
0.4578275,
|
| 19 |
-
0.40821073
|
| 20 |
-
],
|
| 21 |
-
"image_std": [
|
| 22 |
-
0.26862954,
|
| 23 |
-
0.26130258,
|
| 24 |
-
0.27577711
|
| 25 |
-
],
|
| 26 |
-
"return_tensor": true,
|
| 27 |
-
"data_format": "channels_last"
|
| 28 |
}
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"library_name": "zeromodels",
|
| 3 |
+
"zeromodels_version": "1.1.3",
|
| 4 |
+
"preprocessor_module": "zeromodels.models.owlv2",
|
| 5 |
+
"preprocessor_class": "Owlv2ImageProcessor",
|
| 6 |
+
"variant": "owlv2-base-patch16",
|
| 7 |
+
"size": {
|
| 8 |
+
"height": 960,
|
| 9 |
+
"width": 960
|
| 10 |
+
},
|
| 11 |
+
"resample": "bicubic",
|
| 12 |
+
"do_rescale": true,
|
| 13 |
+
"rescale_factor": 0.00392156862745098,
|
| 14 |
+
"do_pad": true,
|
| 15 |
+
"do_normalize": true,
|
| 16 |
+
"image_mean": [
|
| 17 |
+
0.48145466,
|
| 18 |
+
0.4578275,
|
| 19 |
+
0.40821073
|
| 20 |
+
],
|
| 21 |
+
"image_std": [
|
| 22 |
+
0.26862954,
|
| 23 |
+
0.26130258,
|
| 24 |
+
0.27577711
|
| 25 |
+
],
|
| 26 |
+
"return_tensor": true,
|
| 27 |
+
"data_format": "channels_last"
|
| 28 |
}
|