-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathyolo.py
32 lines (25 loc) · 1.06 KB
/
yolo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# import a utility function for loading Roboflow models
from inference import get_model
# import supervision to visualize our results
import supervision as sv
# import cv2 to helo load our image
import cv2
# define the image url to use for inference
image_file = "mixed_data/about-me-mc-slide1.png"
image = cv2.imread(image_file)
# load a pre-trained yolov8n model
model = get_model(model_id="eduprep-ai/4")
# run inference on our chosen image, image can be a url, a numpy array, a PIL image, etc.
results = model.infer(image)
# load the results into the supervision Detections api
detections = sv.Detections.from_inference(results[0].dict(by_alias=True, exclude_none=True))
# create supervision annotators
bounding_box_annotator = sv.BoundingBoxAnnotator()
label_annotator = sv.LabelAnnotator()
# annotate the image with our inference results
annotated_image = bounding_box_annotator.annotate(
scene=image, detections=detections)
annotated_image = label_annotator.annotate(
scene=annotated_image, detections=detections)
# display the image
sv.plot_image(annotated_image)