示例入门代码
from ultralytics import YOLO
import cv2
import matplotlib.pyplot as plt
import matplotlib.image as mpimgdef test():# Create a new YOLO model from scratchmodel = YOLO('yolov8n.yaml')# Load a pretrained YOLO model (recommended for training)model = YOLO('yolov8n.pt')# Train the model using the 'coco128.yaml' dataset for 3 epochsresults = model.train(data='coco128.yaml', epochs=3)# Evaluate the model's performance on the validation setresults = model.val()# Perform object detection on an image using the modelresults = model('./Magic.jpg')res = results[0].plot()cv2.imshow("YOLOv8 Detection", res)cv2.waitKey(10)# Export the model to ONNX format# success = model.export(format='onnx')
if __name__ == '__main__':test()