from ultralytics import YOLO
# Fine-tune a small pretrained detector on your labeled dataset (YOLO format)
model = YOLO("yolo26n.pt")
model.train(data="shelf.yaml", epochs=100, imgsz=640)
# Check per-class quality before shipping, not just the overall score
metrics = model.val()
print("mAP50:", metrics.box.map50)
print("per-class mAP50-95:", metrics.box.maps)
# Run inference and read boxes
results = model.predict("aisle.jpg", conf=0.4)
for box in results[0].boxes:
print(model.names[int(box.cls)], round(float(box.conf), 2), box.xyxy[0].tolist())
# Export for the target runtime
model.export(format="onnx") # ONNX Runtime on servers or the web
model.export(format="coreml") # iOS and macOS
model.export(format="litert") # Android (LiteRT, formerly TFLite)