1from ultralytics import YOLO
2
3# Load the trained YOLOv8 model
4model = YOLO("path/to/best.pt") # Replace with actual model path
5
6# Run inference on a test image
7results = model("path/to/traffic_image.jpg")
8
9# Visualize results
10results.show()
11
12# Access predictions
13for r in results:
14 boxes = r.boxes
15 for box in boxes:
16 print(f"Class: {int(box.cls[0])}, Confidence: {box.conf[0]:.2f}")