-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathyolo-test.py
40 lines (28 loc) · 882 Bytes
/
yolo-test.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
33
34
35
36
37
38
39
40
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed Dec 18 10:57:30 2024
@author: sushu
"""
from PIL import Image
from ultralytics import YOLO
# Load a pretrained YOLO11n model
model = YOLO("./model/best.pt")
# Define path to the image file
source = "./pic/bus.jpg"
# Run inference on the source
results = model(source) # list of Results objects
# # View results
# for r in results:
# print(r.boxes) # print the Boxes object containing the detection bounding boxes
# Visualize the results
for i, r in enumerate(results):
# Plot results image
im_bgr = r.plot() # BGR-order numpy array
im_rgb = Image.fromarray(im_bgr[..., ::-1]) # RGB-order PIL image
# Show results to screen (in supported environments)
r.show()
# Save results to disk
r.save(filename=f"results{i}.jpg")
# Export the model
model.export(format="onnx")