Zero-Shot Object Detection
KerasFormers
Keras
PyTorch
JAX
TensorFlow
owlv2
open-vocabulary
object-detection
Instructions to use zeromodels/owlv2-large-patch14-ensemble with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- KerasFormers
How to use zeromodels/owlv2-large-patch14-ensemble 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/owlv2-large-patch14-ensemble 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/owlv2-large-patch14-ensemble") - Notebooks
- Google Colab
- Kaggle
docs: Unsloth-style KerasFormers model card for owlv2-large-patch14-ensemble
Browse files
README.md
CHANGED
|
@@ -1,21 +1,102 @@
|
|
| 1 |
---
|
| 2 |
pipeline_tag: zero-shot-object-detection
|
| 3 |
license: apache-2.0
|
|
|
|
| 4 |
library_name: kerasformers
|
| 5 |
tags:
|
| 6 |
- keras
|
| 7 |
- kerasformers
|
| 8 |
- owlv2
|
| 9 |
-
-
|
| 10 |
-
-
|
|
|
|
|
|
|
| 11 |
- pytorch
|
|
|
|
|
|
|
| 12 |
---
|
| 13 |
|
| 14 |
-
# owlv2-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
-
|
|
|
|
|
|
|
| 17 |
|
| 18 |
```python
|
| 19 |
-
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
pipeline_tag: zero-shot-object-detection
|
| 3 |
license: apache-2.0
|
| 4 |
+
base_model: google/owlv2-large-patch14-ensemble
|
| 5 |
library_name: kerasformers
|
| 6 |
tags:
|
| 7 |
- keras
|
| 8 |
- kerasformers
|
| 9 |
- owlv2
|
| 10 |
+
- open-vocabulary
|
| 11 |
+
- zero-shot-object-detection
|
| 12 |
+
- object-detection
|
| 13 |
+
- arxiv:2306.09683
|
| 14 |
- pytorch
|
| 15 |
+
- jax
|
| 16 |
+
- tf
|
| 17 |
---
|
| 18 |
|
| 19 |
+
## ***See [our collection](https://huggingface.co/collections/kerasformers/owlv2-6a6a7aaaf7cd6616646d8318) for all versions of OWLv2.***
|
| 20 |
+
|
| 21 |
+
# Run OWLv2 with Keras 3: JAX, PyTorch, or TensorFlow
|
| 22 |
+
|
| 23 |
+
[](https://github.com/IMvision12/KerasFormers) [](https://imvision12.github.io/KerasFormers/owlv2/) [](https://huggingface.co/collections/kerasformers/owlv2-6a6a7aaaf7cd6616646d8318)
|
| 24 |
+
|
| 25 |
+
# kerasformers/owlv2-large-patch14-ensemble
|
| 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 |
+
|
| 29 |
+
OWLv2 keeps OWL-ViT's dual-tower skeleton and per-patch detection head, and scales it with self-training on web image-text pairs. It adds an objectness head (a learned is-this-patch-an-object score) and pads images to a square before resizing, which matters for post-processing target sizes.
|
| 30 |
+
|
| 31 |
+
For more details on the model, please go to Google's original [model card](https://huggingface.co/google/owlv2-large-patch14-ensemble).
|
| 32 |
+
|
| 33 |
+
Pure-**Keras 3** conversion of [`google/owlv2-large-patch14-ensemble`](https://huggingface.co/google/owlv2-large-patch14-ensemble) for [kerasformers](https://github.com/IMvision12/KerasFormers). 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 |
+
|
| 37 |
+
## ✨ Quick start
|
| 38 |
|
| 39 |
```python
|
| 40 |
+
import os
|
| 41 |
+
os.environ["KERAS_BACKEND"] = "torch" # or "jax" / "tensorflow"
|
| 42 |
+
|
| 43 |
+
from PIL import Image
|
| 44 |
+
from kerasformers.models.owlv2 import (
|
| 45 |
+
Owlv2Detect,
|
| 46 |
+
Owlv2Processor,
|
| 47 |
+
Owlv2ImageProcessor,
|
| 48 |
+
)
|
| 49 |
+
|
| 50 |
+
model = Owlv2Detect.from_weights("kerasformers/owlv2-large-patch14-ensemble")
|
| 51 |
+
processor = Owlv2Processor.from_weights("kerasformers/owlv2-large-patch14-ensemble")
|
| 52 |
+
image_processor = Owlv2ImageProcessor()
|
| 53 |
+
|
| 54 |
+
image = Image.open("your_image.jpg").convert("RGB")
|
| 55 |
+
prompts = ["a photo of a mug", "a photo of a knife"]
|
| 56 |
+
inputs = processor(text=[prompts], images=image)
|
| 57 |
+
output = model(
|
| 58 |
+
{
|
| 59 |
+
"input_ids": inputs["input_ids"],
|
| 60 |
+
"pixel_values": inputs["pixel_values"],
|
| 61 |
+
}
|
| 62 |
+
)
|
| 63 |
+
results = image_processor.post_process_object_detection(
|
| 64 |
+
output,
|
| 65 |
+
threshold=0.1,
|
| 66 |
+
target_sizes=[(image.height, image.width)],
|
| 67 |
+
text_labels=[prompts],
|
| 68 |
+
)[0]
|
| 69 |
+
for score, name, box in zip(
|
| 70 |
+
results["scores"], results["text_labels"], results["boxes"]
|
| 71 |
+
):
|
| 72 |
+
print(f"{name}: {float(score):.3f} {box}")
|
| 73 |
```
|
| 74 |
+
|
| 75 |
+
Load any OWL-ViT / OWLv2 variant the same way with `from_weights("kerasformers/<variant>")` (use `Owlv2Detect` for this repo):
|
| 76 |
+
|
| 77 |
+
| Variant | Hub | Family |
|
| 78 |
+
|---|---|---|
|
| 79 |
+
| `owlvit-base-patch32` | [`kerasformers/owlvit-base-patch32`](https://huggingface.co/kerasformers/owlvit-base-patch32) | OWL-ViT |
|
| 80 |
+
| `owlvit-base-patch16` | [`kerasformers/owlvit-base-patch16`](https://huggingface.co/kerasformers/owlvit-base-patch16) | OWL-ViT |
|
| 81 |
+
| `owlvit-large-patch14` | [`kerasformers/owlvit-large-patch14`](https://huggingface.co/kerasformers/owlvit-large-patch14) | OWL-ViT |
|
| 82 |
+
| `owlv2-base-patch16` | [`kerasformers/owlv2-base-patch16`](https://huggingface.co/kerasformers/owlv2-base-patch16) | OWLv2 |
|
| 83 |
+
| `owlv2-base-patch16-ensemble` | [`kerasformers/owlv2-base-patch16-ensemble`](https://huggingface.co/kerasformers/owlv2-base-patch16-ensemble) | OWLv2 |
|
| 84 |
+
| `owlv2-base-patch16-finetuned` | [`kerasformers/owlv2-base-patch16-finetuned`](https://huggingface.co/kerasformers/owlv2-base-patch16-finetuned) | OWLv2 |
|
| 85 |
+
| `owlv2-large-patch14` | [`kerasformers/owlv2-large-patch14`](https://huggingface.co/kerasformers/owlv2-large-patch14) | OWLv2 |
|
| 86 |
+
| `owlv2-large-patch14-ensemble` | [`kerasformers/owlv2-large-patch14-ensemble`](https://huggingface.co/kerasformers/owlv2-large-patch14-ensemble) | OWLv2 |
|
| 87 |
+
| `owlv2-large-patch14-finetuned` | [`kerasformers/owlv2-large-patch14-finetuned`](https://huggingface.co/kerasformers/owlv2-large-patch14-finetuned) | OWLv2 |
|
| 88 |
+
|
| 89 |
+
## Tips
|
| 90 |
+
|
| 91 |
+
- Set `KERAS_BACKEND` **before** importing Keras / kerasformers.
|
| 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/KerasFormers/owlv2/) and [Loading Weights](https://imvision12.github.io/KerasFormers/loading_weights/).
|
| 96 |
+
- Community / upstream safetensors still work via the `hf:` prefix, e.g. `Owlv2Detect.from_weights("hf:google/owlv2-large-patch14-ensemble")`.
|
| 97 |
+
|
| 98 |
+
## Special Thanks
|
| 99 |
+
|
| 100 |
+
A huge thank you to the Google OWLv2 authors for creating and releasing these models.
|
| 101 |
+
|
| 102 |
+
License: Apache 2.0.
|