Views
No views yet
v9b_best.pt (Ultralytics format) and v9b_best.onnx are in this repo.
Use the ONNX path if you want to avoid the AGPL Ultralytics runtime
dependency.pip install onnxruntime opencv-python numpy1import cv2, numpy as np, onnxruntime as ort
2
3sess = ort.InferenceSession("v9b_best.onnx",
4 providers=["CPUExecutionProvider"]) # or CUDAExecutionProvider
5img = cv2.imread("path/to/frame.jpg")
6# preprocess: BGR->RGB, resize to 1280, normalize 0-1, NCHW
7resized = cv2.resize(img, (1280, 1280))
8x = resized[..., ::-1].transpose(2, 0, 1).astype(np.float32) / 255.0
9x = x[None] # (1, 3, 1280, 1280)
10
11outputs = sess.run(None, {sess.get_inputs()[0].name: x})
12# outputs[0] shape: (1, 5, N) for single-class YOLOv9 — x,y,w,h,conf per anchor
13# Apply NMS + confidence threshold; see ultralytics/utils/ops.py for reference1from ultralytics import YOLO
2model = YOLO("v9b_best.pt")
3results = model("path/to/frame.jpg")
4for r in results:
5 for box in r.boxes:
6 x1, y1, x2, y2 = box.xyxy[0].tolist()
7 conf = box.conf[0].item()
8 print(f"ball at ({x1:.0f},{y1:.0f})-({x2:.0f},{y2:.0f}) conf={conf:.2f}")conf > 0.2 — at amateur-distance footage ball-class confidence typically
sits in 0.15-0.35.