Instructions to use kerasformers/owlvit-base-patch32 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- KerasFormers
How to use kerasformers/owlvit-base-patch32 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/owlvit-base-patch32 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/owlvit-base-patch32") - Notebooks
- Google Colab
- Kaggle
See our collection for all versions of OWL-ViT.
Run OWL-ViT with Keras 3: JAX, PyTorch, or TensorFlow
kerasformers/owlvit-base-patch32
Paper: Simple Open-Vocabulary Object Detection with Vision Transformers (arXiv:2205.06230) · HF Papers
OWL-ViT detects objects described by free text, with no fixed class list. It starts from a CLIP-style vision and text encoder, then drops CLIP's pooling and attaches a lightweight box head to every patch token. Each patch becomes a detection candidate, scored by cosine similarity against your text queries.
For more details on the model, please go to Google's original model card.
Pure-Keras 3 conversion of google/owlvit-base-patch32 for kerasformers. One implementation runs unmodified on TensorFlow / Torch / JAX.
This is an open-vocabulary object detection checkpoint (OwlViTDetect): pass free-text prompts at inference time.
✨ Quick start
import os
os.environ["KERAS_BACKEND"] = "torch" # or "jax" / "tensorflow"
from PIL import Image
from kerasformers.models.owlvit import (
OwlViTDetect,
OwlViTProcessor,
OwlViTImageProcessor,
)
model = OwlViTDetect.from_weights("kerasformers/owlvit-base-patch32")
processor = OwlViTProcessor.from_weights("kerasformers/owlvit-base-patch32")
image_processor = OwlViTImageProcessor()
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 OwlViTDetect for this repo):
| Variant | Hub | Family |
|---|---|---|
owlvit-base-patch32 |
kerasformers/owlvit-base-patch32 |
OWL-ViT |
owlvit-base-patch16 |
kerasformers/owlvit-base-patch16 |
OWL-ViT |
owlvit-large-patch14 |
kerasformers/owlvit-large-patch14 |
OWL-ViT |
owlv2-base-patch16 |
kerasformers/owlv2-base-patch16 |
OWLv2 |
owlv2-base-patch16-ensemble |
kerasformers/owlv2-base-patch16-ensemble |
OWLv2 |
owlv2-base-patch16-finetuned |
kerasformers/owlv2-base-patch16-finetuned |
OWLv2 |
owlv2-large-patch14 |
kerasformers/owlv2-large-patch14 |
OWLv2 |
owlv2-large-patch14-ensemble |
kerasformers/owlv2-large-patch14-ensemble |
OWLv2 |
owlv2-large-patch14-finetuned |
kerasformers/owlv2-large-patch14-finetuned |
OWLv2 |
Tips
- Set
KERAS_BACKENDbefore 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)astarget_sizescarefully (see the OWLv2 docs for the padding trap). - See OWL-ViT docs and Loading Weights.
- Community / upstream safetensors still work via the
hf:prefix, e.g.OwlViTDetect.from_weights("hf:google/owlvit-base-patch32").
Special Thanks
A huge thank you to the Google OWL-ViT authors for creating and releasing these models.
License: Apache 2.0.
- Downloads last month
- 29
Model tree for kerasformers/owlvit-base-patch32
Base model
google/owlvit-base-patch32