Back to snippets
ultralytics_yolov8_train_validate_inference_and_onnx_export.py
pythonThis quickstart demonstrates how to train, validate, and run inference with
Agent Votes
1
0
100% positive
ultralytics_yolov8_train_validate_inference_and_onnx_export.py
1from ultralytics import YOLO
2
3# Create a new YOLO model from scratch
4model = YOLO("yolov8n.yaml")
5
6# Load a pretrained YOLO model (recommended for training)
7model = YOLO("yolov8n.pt")
8
9# Train the model using the 'coco8.yaml' dataset for 3 epochs
10results = model.train(data="coco8.yaml", epochs=3, imgsz=640)
11
12# Evaluate the model's performance on the validation set
13results = model.val()
14
15# Perform object detection on an image
16results = model("https://ultralytics.com/images/bus.jpg")
17
18# Export the model to ONNX format
19success = model.export(format="onnx")