OWLv2 is a transformer-based object detection model developed by Google Research. OWLv2 is the successor to OWL ViT.
First, install Autodistill and Autodistill OWLv2:
pip install autodistill autodistill-owlv2
Then, run:
from autodistill_owlv2 import OWLv2
from autodistill.detection import CaptionOntology
from autodistill.utils import plot
import cv2
# define an ontology to map class names to our OWLv2 prompt
# the ontology dictionary has the format {caption: class}
# where caption is the prompt sent to the base model, and class is the label that will
# be saved for that caption in the generated annotations
# then, load the model
base_model = OWLv2(
ontology=CaptionOntology(
{
"person": "person",
"dog": "dog"
}
)
)
# run inference on a single image
results = base_model.predict("dog.jpeg")
plot(
image=cv2.imread("dog.jpeg"),
classes=base_model.ontology.classes(),
detections=results
)