-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdetect.py
47 lines (33 loc) · 1.27 KB
/
detect.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
41
42
43
44
45
46
47
##Train##
from ultralytics import YOLO
# Load a model
model = YOLO('yolov8n.yaml') # build a new model from YAML
model = YOLO('yolov8n.pt') # load a pretrained model (recommended for training)
model = YOLO('yolov8n.yaml').load('yolov8n.pt') # build from YAML and transfer weights
# Train the model
results = model.train(data='coco128.yaml', epochs=100, imgsz=640)
##validate trained YOLOv8n model##
# Load a model
model = YOLO('yolov8n.pt') # load an official model
#model = YOLO('path/to/best.pt') # load a custom model
# Validate the model
metrics = model.val() # no arguments needed, dataset and settings remembered
metrics.box.map # map50-95
metrics.box.map50 # map50
metrics.box.map75 # map75
metrics.box.maps # a list contains map50-95 of each category
# Predict
#Use a trained YOLOv8n model
# to run predictions on images.
# Load a model
model = YOLO('yolov8n.pt') # load an official model
#model = YOLO('path/to/best.pt') # load a custom model
# Predict with the model
results = model('https://ultralytics.com/images/bus.jpg') # predict on an image
#Export
#maybe try torch for format
# Load a model
model = YOLO('yolov8n.pt') # load an official model
#model = YOLO('path/to/best.pt') # load a custom trained model
# Export the model
model.export(format='onnx')