Upload README.md with huggingface_hub
Browse files
README.md
CHANGED
|
@@ -1,26 +1,146 @@
|
|
| 1 |
-
|
| 2 |
-
tags:
|
| 3 |
-
- ml-intern
|
| 4 |
-
---
|
| 5 |
|
| 6 |
-
|
| 7 |
|
| 8 |
-
|
| 9 |
-
## Generated by ML Intern
|
| 10 |
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
-
|
| 14 |
-
- Source code: https://github.com/huggingface/ml-intern
|
| 15 |
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
```python
|
| 19 |
-
from
|
| 20 |
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
```
|
| 25 |
|
| 26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Golf Ball Tracker for Mobile Phone Camera
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
+
A lightweight, real-time golf ball detection and tracking model optimized for mobile deployment.
|
| 4 |
|
| 5 |
+
## Model Overview
|
|
|
|
| 6 |
|
| 7 |
+
- **Architecture**: YOLOv8-nano (3M parameters, 8.1 GFLOPs)
|
| 8 |
+
- **Training Data**: 559 real ball images + 500 synthetic golf ball images
|
| 9 |
+
- **Test Performance**: mAP50 = 81.2%, mAP50-95 = 58.6%
|
| 10 |
+
- **Formats**: PyTorch (.pt), ONNX (.onnx)
|
| 11 |
+
- **Input Size**: 640x640
|
| 12 |
+
- **Target FPS**: ~30 FPS on modern mobile devices (via ONNX Runtime or TFLite)
|
| 13 |
|
| 14 |
+
## Use Cases
|
|
|
|
| 15 |
|
| 16 |
+
- **Golf shot analysis**: Track ball flight from tee to landing
|
| 17 |
+
- **Swing coaching**: Visual feedback on ball trajectory
|
| 18 |
+
- **Mobile golf apps**: Real-time ball tracking using phone camera
|
| 19 |
+
- **Driving range**: Automated ball flight recording
|
| 20 |
+
|
| 21 |
+
## Mobile Deployment
|
| 22 |
+
|
| 23 |
+
### iOS (CoreML)
|
| 24 |
+
```python
|
| 25 |
+
from ultralytics import YOLO
|
| 26 |
+
model = YOLO("best.pt")
|
| 27 |
+
model.export(format="coreml", imgsz=640)
|
| 28 |
+
```
|
| 29 |
+
|
| 30 |
+
### Android (TFLite)
|
| 31 |
+
```python
|
| 32 |
+
from ultralytics import YOLO
|
| 33 |
+
model = YOLO("best.pt")
|
| 34 |
+
model.export(format="tflite", imgsz=640, int8=True)
|
| 35 |
+
```
|
| 36 |
+
|
| 37 |
+
### Cross-Platform (ONNX Runtime)
|
| 38 |
+
```python
|
| 39 |
+
import onnxruntime as ort
|
| 40 |
+
session = ort.InferenceSession("best.onnx")
|
| 41 |
+
# Use session for inference on any platform
|
| 42 |
+
```
|
| 43 |
+
|
| 44 |
+
## Quick Start
|
| 45 |
+
|
| 46 |
+
```python
|
| 47 |
+
from ultralytics import YOLO
|
| 48 |
+
|
| 49 |
+
# Load model
|
| 50 |
+
model = YOLO("best.pt")
|
| 51 |
+
|
| 52 |
+
# Detect golf balls in an image
|
| 53 |
+
results = model("golf_shot.jpg")
|
| 54 |
+
results[0].show()
|
| 55 |
+
|
| 56 |
+
# Track ball across video frames
|
| 57 |
+
for frame in video_stream:
|
| 58 |
+
results = model.track(frame, persist=True)
|
| 59 |
+
# results[0].boxes.xywh provides bounding boxes
|
| 60 |
+
```
|
| 61 |
+
|
| 62 |
+
## Tracking Pipeline
|
| 63 |
+
|
| 64 |
+
For full trajectory tracking with Kalman filtering and ballistic prediction, see `golf_ball_tracker.py`:
|
| 65 |
+
|
| 66 |
+
```python
|
| 67 |
+
from golf_ball_tracker import GolfBallTracker
|
| 68 |
+
|
| 69 |
+
tracker = GolfBallTracker("best.onnx")
|
| 70 |
+
tracker.track_video("input.mp4", "output_tracked.mp4")
|
| 71 |
+
```
|
| 72 |
+
|
| 73 |
+
The tracker includes:
|
| 74 |
+
- **YOLO detection**: Finds golf ball in each frame
|
| 75 |
+
- **Kalman filtering**: Smooths trajectory, handles missed detections
|
| 76 |
+
- **Ballistic prediction**: Predicts flight path when ball is occluded or too small
|
| 77 |
+
- **Trajectory history**: Stores last 100 positions for visualization
|
| 78 |
+
|
| 79 |
+
## Dataset
|
| 80 |
+
|
| 81 |
+
The model was trained on:
|
| 82 |
+
1. **Zenodo Accurate Balls Detection** dataset (559 images of various sports balls)
|
| 83 |
+
2. **500 synthetic golf ball images** with varied:
|
| 84 |
+
- Backgrounds (sky, grass, golf course, indoor, dark)
|
| 85 |
+
- Ball sizes (4-40 pixels radius, simulating distance)
|
| 86 |
+
- Motion blur (0-5 levels, simulating high-speed flight)
|
| 87 |
+
- Brightness variations (0.4-1.7x)
|
| 88 |
+
- Noise and lighting changes
|
| 89 |
+
|
| 90 |
+
## Training Recipe
|
| 91 |
|
| 92 |
```python
|
| 93 |
+
from ultralytics import YOLO
|
| 94 |
|
| 95 |
+
model = YOLO("yolov8n.pt")
|
| 96 |
+
model.train(
|
| 97 |
+
data="golf_ball.yaml",
|
| 98 |
+
epochs=5, # Short training (CPU-friendly)
|
| 99 |
+
imgsz=640,
|
| 100 |
+
batch=4,
|
| 101 |
+
device="cpu",
|
| 102 |
+
augment=True,
|
| 103 |
+
mosaic=1.0,
|
| 104 |
+
scale=0.5, # Critical for small object detection
|
| 105 |
+
hsv_h=0.015,
|
| 106 |
+
hsv_s=0.7,
|
| 107 |
+
hsv_v=0.4,
|
| 108 |
+
)
|
| 109 |
```
|
| 110 |
|
| 111 |
+
**Key insights for golf ball detection**:
|
| 112 |
+
- High-resolution features (640x640 input)
|
| 113 |
+
- Heavy scale augmentation (balls appear at different distances)
|
| 114 |
+
- Motion blur augmentation (golf balls move at 150+ mph)
|
| 115 |
+
- Brightness variation (white ball against sky/grass)
|
| 116 |
+
|
| 117 |
+
## Performance Tips for Mobile
|
| 118 |
+
|
| 119 |
+
1. **Use 320x320 input** for 4x faster inference (small accuracy trade-off)
|
| 120 |
+
2. **Quantize to INT8** for 2-4x speedup on mobile NPUs
|
| 121 |
+
3. **Frame skipping**: Run detection every 3rd frame, interpolate between
|
| 122 |
+
4. **ROI tracking**: After initial detection, only search nearby region
|
| 123 |
+
5. **Hardware acceleration**: Use NNAPI (Android) or CoreML (iOS)
|
| 124 |
+
|
| 125 |
+
## Limitations
|
| 126 |
+
|
| 127 |
+
- Model trained on mixed sports ball data (football, etc.) + synthetic golf balls
|
| 128 |
+
- Real golf ball flight data would improve performance significantly
|
| 129 |
+
- Small balls at extreme distances (>100 yards) may be challenging
|
| 130 |
+
- Motion blur at very high speeds may reduce detection rate
|
| 131 |
+
- Night/low-light conditions not specifically trained
|
| 132 |
+
|
| 133 |
+
## Citation
|
| 134 |
+
|
| 135 |
+
```bibtex
|
| 136 |
+
@software{golf_ball_tracker,
|
| 137 |
+
title = {Golf Ball Tracker for Mobile Phone Camera},
|
| 138 |
+
author = {ML Intern},
|
| 139 |
+
year = {2026},
|
| 140 |
+
url = {https://huggingface.co/notjulietxd/golf-ball-tracker}
|
| 141 |
+
}
|
| 142 |
+
```
|
| 143 |
+
|
| 144 |
+
## License
|
| 145 |
+
|
| 146 |
+
Apache-2.0
|