-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpredict.py
24 lines (18 loc) · 818 Bytes
/
predict.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
from ultralytics import YOLO
from PIL import Image
import cv2
model_path = "D:/projects/pyprojects/yolo-detection/runs/detect/train3/weights/best.onnx"
print("model path={}".format(model_path))
model = YOLO(model_path)
# accepts all formats - image/dir/Path/URL/video/PIL/ndarray. 0 for webcam
results = model.predict(source="0") # from video
#results = model.track(source="0", show=True)
#results = model.predict(source="folder", show=True) # Display preds. Accepts all YOLO predict arguments
# from PIL
#im1 = Image.open("bus.jpg")
#results = model.predict(source=im1, save=True) # save plotted images
# from ndarray
#im2 = cv2.imread("bus.jpg")
#results = model.predict(source=im2, save=True, save_txt=True) # save predictions as labels
# from list of PIL/ndarray
#results = model.predict(source=[im1, im2])