2023-DnB-Project/example/demo.py

21 lines
1007 B
Python
Raw Normal View History

2023-06-26 17:18:00 +08:00
from ultralytics import YOLO
# from ultralytics.yolo.utils.benchmarks import benchmark
# Load a model
# model = YOLO("yolov8n.yaml") # build a new model from scratch
2023-06-29 23:49:53 +08:00
# model = YOLO("../runs/detect/train3/weights/best.pt") # zhou
model = YOLO("../runs/detect/train4/weights/best.pt") # 1000 img, mine
model = YOLO("../runs/detect/train2/weights/best.pt") # 1000 img, based on 3000 img
# model = YOLO("../../../project/runs/detect/train3/weights/best.pt") # 3000 img, mine
2023-06-26 17:18:00 +08:00
# Use the model
# model.train(data="coco128.yaml", epochs=3,workers=0) # train the model,workers=0 if windows
# metrics = model.val() # evaluate model performance on the validation set
2023-06-29 23:49:53 +08:00
img_path = "./image"
results = model.predict(img_path, save = True) # device=0 by default, conf:置信度阈值
2023-06-26 17:18:00 +08:00
# results = model.predict(img_path,save=True,classes=[0,2],conf=0.5) # i.e. classes=0,classes=[0,3,4]
# save detection results *
# results = model.predict(img_path,save=True,save_txt=True,classes=0,conf=0.4)