-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModel Inference Testing.py
More file actions
32 lines (24 loc) · 889 Bytes
/
Model Inference Testing.py
File metadata and controls
32 lines (24 loc) · 889 Bytes
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
from ultralytics import YOLO
import cv2
model = YOLO("models/best.pt")
# Define path to test image
image_path = "images/IMAGE_PATH.jpg"
# Run inference on the image
results = model.predict(image_path,
conf=0.5,
imgsz=1920,
iou = 0.4,
retina_masks=False
)
# Loop over each result and plot the segmentation masks
for result in results:
# Adjust to display labels, masks, and bounding boxes as needed.
segmented_img = result.plot(labels=True,
masks=True,
boxes=False
)
# Display the resulting image using OpenCV
cv2.imshow("YOLOv8 Segmentation Inference", segmented_img)
# Wait until a key is pressed
cv2.waitKey(0)
cv2.destroyAllWindows()