Zero-Shot Object Detection
KerasFormers
Keras
PyTorch
JAX
TensorFlow
owlv2
open-vocabulary
object-detection
Instructions to use kerasformers/owlv2-base-patch16-ensemble with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- KerasFormers
How to use kerasformers/owlv2-base-patch16-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 kerasformers/owlv2-base-patch16-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://kerasformers/owlv2-base-patch16-ensemble") - Notebooks
- Google Colab
- Kaggle
| pipeline_tag: zero-shot-object-detection | |
| license: apache-2.0 | |
| base_model: google/owlv2-base-patch16-ensemble | |
| library_name: kerasformers | |
| tags: | |
| - keras | |
| - kerasformers | |
| - owlv2 | |
| - open-vocabulary | |
| - zero-shot-object-detection | |
| - object-detection | |
| - arxiv:2306.09683 | |
| - pytorch | |
| - jax | |
| - tf | |
| ## ***See [our collection](https://huggingface.co/collections/kerasformers/owlv2-6a6a7aaaf7cd6616646d8318) for all versions of OWLv2.*** | |
| # Run OWLv2 with Keras 3: JAX, PyTorch, or TensorFlow | |
| [](https://github.com/IMvision12/KerasFormers) [](https://imvision12.github.io/KerasFormers/owlv2/) [](https://huggingface.co/collections/kerasformers/owlv2-6a6a7aaaf7cd6616646d8318) | |
| # kerasformers/owlv2-base-patch16-ensemble | |
| Paper: [Scaling Open-Vocabulary Object Detection (arXiv:2306.09683)](https://arxiv.org/abs/2306.09683) · [HF Papers](https://huggingface.co/papers/2306.09683) | |
| 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. | |
| For more details on the model, please go to Google's original [model card](https://huggingface.co/google/owlv2-base-patch16-ensemble). | |
| Pure-**Keras 3** conversion of [`google/owlv2-base-patch16-ensemble`](https://huggingface.co/google/owlv2-base-patch16-ensemble) for [kerasformers](https://github.com/IMvision12/KerasFormers). One implementation runs unmodified on **TensorFlow / Torch / JAX**. | |
| This is an **open-vocabulary object detection** checkpoint (`Owlv2Detect`): pass free-text prompts at inference time. | |
| ## ✨ Quick start | |
| ```python | |
| import os | |
| os.environ["KERAS_BACKEND"] = "torch" # or "jax" / "tensorflow" | |
| from PIL import Image | |
| from kerasformers.models.owlv2 import ( | |
| Owlv2Detect, | |
| Owlv2Processor, | |
| Owlv2ImageProcessor, | |
| ) | |
| model = Owlv2Detect.from_weights("kerasformers/owlv2-base-patch16-ensemble") | |
| processor = Owlv2Processor.from_weights("kerasformers/owlv2-base-patch16-ensemble") | |
| image_processor = Owlv2ImageProcessor.from_weights("kerasformers/owlv2-base-patch16-ensemble") | |
| image = Image.open("your_image.jpg").convert("RGB") | |
| prompts = ["a photo of a mug", "a photo of a knife"] | |
| inputs = processor(text=[prompts], images=image) | |
| output = model( | |
| { | |
| "input_ids": inputs["input_ids"], | |
| "pixel_values": inputs["pixel_values"], | |
| } | |
| ) | |
| results = image_processor.post_process_object_detection( | |
| output, | |
| threshold=0.1, | |
| target_sizes=[(image.height, image.width)], | |
| text_labels=[prompts], | |
| )[0] | |
| for score, name, box in zip( | |
| results["scores"], results["text_labels"], results["boxes"] | |
| ): | |
| print(f"{name}: {float(score):.3f} {box}") | |
| ``` | |
| Load any OWL-ViT / OWLv2 variant the same way with `from_weights("kerasformers/<variant>")` (use `Owlv2Detect` for this repo): | |
| | Variant | Hub | Family | | |
| |---|---|---| | |
| | `owlvit-base-patch32` | [`kerasformers/owlvit-base-patch32`](https://huggingface.co/kerasformers/owlvit-base-patch32) | OWL-ViT | | |
| | `owlvit-base-patch16` | [`kerasformers/owlvit-base-patch16`](https://huggingface.co/kerasformers/owlvit-base-patch16) | OWL-ViT | | |
| | `owlvit-large-patch14` | [`kerasformers/owlvit-large-patch14`](https://huggingface.co/kerasformers/owlvit-large-patch14) | OWL-ViT | | |
| | `owlv2-base-patch16` | [`kerasformers/owlv2-base-patch16`](https://huggingface.co/kerasformers/owlv2-base-patch16) | OWLv2 | | |
| | `owlv2-base-patch16-ensemble` | [`kerasformers/owlv2-base-patch16-ensemble`](https://huggingface.co/kerasformers/owlv2-base-patch16-ensemble) | OWLv2 | | |
| | `owlv2-base-patch16-finetuned` | [`kerasformers/owlv2-base-patch16-finetuned`](https://huggingface.co/kerasformers/owlv2-base-patch16-finetuned) | OWLv2 | | |
| | `owlv2-large-patch14` | [`kerasformers/owlv2-large-patch14`](https://huggingface.co/kerasformers/owlv2-large-patch14) | OWLv2 | | |
| | `owlv2-large-patch14-ensemble` | [`kerasformers/owlv2-large-patch14-ensemble`](https://huggingface.co/kerasformers/owlv2-large-patch14-ensemble) | OWLv2 | | |
| | `owlv2-large-patch14-finetuned` | [`kerasformers/owlv2-large-patch14-finetuned`](https://huggingface.co/kerasformers/owlv2-large-patch14-finetuned) | OWLv2 | | |
| ## Tips | |
| - Set `KERAS_BACKEND` **before** importing Keras / kerasformers. | |
| - Prefer `Processor.from_weights(...)` so image size matches the variant. | |
| - Open-vocab thresholds are often much lower than closed-set detectors (try `0.1`). | |
| - OWLv2 pads to square before resize; pass the original `(height, width)` as `target_sizes` carefully (see the OWLv2 docs for the padding trap). | |
| - See [OWLv2 docs](https://imvision12.github.io/KerasFormers/owlv2/) and [Loading Weights](https://imvision12.github.io/KerasFormers/loading_weights/). | |
| - Community / upstream safetensors still work via the `hf:` prefix, e.g. `Owlv2Detect.from_weights("hf:google/owlv2-base-patch16-ensemble")`. | |
| ## Special Thanks | |
| A huge thank you to the Google OWLv2 authors for creating and releasing these models. | |
| License: Apache 2.0. | |