YOLOv7
Use YOLOv7 instance segmentation through our Serverless Hosted API
Default COCO aliases
Code sample
pip install inference-sdk supervision opencv-pythonimport os
import urllib.request
import cv2
import supervision as sv
from inference_sdk import InferenceHTTPClient
image_url = "https://storage.googleapis.com/com-roboflow-marketing/notebooks/examples/bicycle.png"
image_path = "bicycle.png"
urllib.request.urlretrieve(image_url, image_path)
image = cv2.imread(image_path)
client = InferenceHTTPClient(
api_url="https://serverless.roboflow.com",
api_key=os.getenv("API_KEY"),
)
results = client.infer(image_path, model_id="your-project/1")
detections = sv.Detections.from_inference(results)
mask_annotator = sv.MaskAnnotator()
label_annotator = sv.LabelAnnotator()
labels = [
f"{cls} {conf:.2f}"
for cls, conf in zip(detections.data.get("class_name", []), detections.confidence)
]
annotated = mask_annotator.annotate(scene=image.copy(), detections=detections)
annotated = label_annotator.annotate(scene=annotated, detections=detections, labels=labels)
cv2.imwrite("annotated.png", annotated)Last updated
Was this helpful?