OwlV2
Dedicated Deployment या self-hosted Inference पर one-shot object detection के लिए OwlV2 का उपयोग करें
कोड नमूना
3
मॉडल चलाएँ
import base64
import os
import cv2
import numpy as np
import requests
import supervision as sv
URL = "https://your-deployment.roboflow.cloud"
content = requests.get("https://media.roboflow.com/notebooks/examples/dog.jpeg").content
image = cv2.imdecode(np.frombuffer(content, np.uint8), cv2.IMREAD_COLOR)
_, buffer = cv2.imencode(".jpg", image)
image_base64 = base64.b64encode(buffer).decode("utf-8")
response = requests.post(
f"{URL}/owlv2/infer",
json={
"api_key": os.environ["ROBOFLOW_API_KEY"],
"image": {"type": "base64", "value": image_base64},
"training_data": [{
"image": {"type": "base64", "value": image_base64},
"boxes": [{"x": 360, "y": 800, "w": 500, "h": 500, "cls": "dog"}],
}],
"confidence": 0.99,
},
)
preds = response.json()["predictions"]
xyxys = [
[p["x"] - p["width"] / 2, p["y"] - p["height"] / 2,
p["x"] + p["width"] / 2, p["y"] + p["height"] / 2]
for p in preds
]
detections = sv.Detections(
xyxy=np.array(xyxys, dtype=float),
class_id=np.array([p.get("class_id", 0) for p in preds]),
confidence=np.array([p["confidence"] for p in preds], dtype=float),
data={"class_name": np.array([p["class"] for p in preds])},
)
labels = [f"{p['class']} {p['confidence']:.2f}" for p in preds]
annotated = sv.BoxAnnotator().annotate(image.copy(), detections)
annotated = sv.LabelAnnotator().annotate(annotated, detections, labels=labels)
cv2.imwrite("dog_annotated.png", annotated)
Inference speed
मॉडल
विलंबता (ms)
अंतिम अपडेट
क्या यह उपयोगी था?