Football (soccer, if you must) ball detection — YOLO26 + Core ML, real-time on iPhone (box2boxcam v1.0)
box2boxcam-ball-v1.0 is a YOLO26-small soccer ball detector for football matches filmed on amateur and grassroots pitches. It is meant for a phone on the sideline, where it finds the ball in each frame so that an auto-tracking camera, such as a phone on a DockKit gimbal, can follow the play. It ships as PyTorch weights and as a Core ML package for real-time ball tracking on iPhone. It detects one class, "sports ball", and does not find players.
Quick start
Python (Ultralytics):
from huggingface_hub import hf_hub_download
from ultralytics import YOLO
weights = hf_hub_download(
repo_id="Totorotibo84/box2boxcam-football-ball-detection",
filename="box2boxcam-ball-v1.0.pt",
)
model = YOLO(weights)
results = model.predict("match.mp4", imgsz=960, conf=0.25)
Swift / Core ML (Vision), with box2boxcam-ball-v1.0.mlpackage added to your Xcode target:
let ballModel = try VNCoreMLModel(for: MLModel(contentsOf: compiledModelURL))
let request = VNCoreMLRequest(model: ballModel)
try VNImageRequestHandler(cgImage: frame, options: [:]).perform([request])
let balls = request.results as? [VNRecognizedObjectObservation]
The Core ML package is FP16 with non-maximum suppression included.
Intended use and out of scope
- In scope: football (soccer) matches filmed with a phone at amateur and grassroots level, where the ball is visible at a usable size.
- Out of scope: broadcast TV footage (not in the training data), other sports or balls (not evaluated), and small, far-away balls (recall is low there, see below).
Training data
3,451 images: 3,283 for training and 168 for validation.
- 1,941 filmed by the author on amateur pitches and at home
- 603 from short online videos
- 907 from one online video (739 train, 168 validation)
Third-party footage is not redistributed. Boxes come from automatic proposals reviewed by clicking; they are not hand-drawn ground truth.
Provenance and privacy:
- Author's footage: in the public dataset, heads are blurred automatically with a pose model. Small far heads (under about 20 px) may remain, and players can still be recognisable by other cues. The model itself was trained on the unblurred frames, and on a few of the author's clips that are not part of the public dataset.
- Third-party clips: referenced by URL only.
- Frames were sent to third-party model APIs to propose ball boxes. Those proposals were reviewed by the author, ball and unsure candidates by clicking.
Training recipe
- Base:
yolo26s.pt(Ultralytics YOLO26-small), COCO-pretrained - One class, "sports ball"; input size 960 px
- 30 epochs, early stopping patience 8, batch 8, AdamW, initial learning rate 0.001, seed 42
- Run on Hugging Face Jobs, a10g-small GPU
Results (held-out amateur match)
A reserved match never used for training: 396 frames, 219 balls, of which 149 are 16 px or smaller. Matching at IoU >= 0.5, 960 px input. The numbers below were measured on the original unblurred frames; on the published (head-blurred) test split the model scores 99 / 100, 92 / 52, 85 / 22 and 82 / 4 (see the comparison with stock YOLO26 below).
| Confidence | True positives | False positives |
|---|---|---|
| 0.25 | 100 | 103 |
| 0.35 | 93 | 60 |
| 0.45 | 86 | 30 |
| 0.55 | 81 | 3 |
- At 0.25: recall 100/219 (45.7 %), precision 100/203 (49.3 %).
- Small balls: 57 of 149 found at 0.25 (38 %).
- Limitation: fewer than half the balls are found at usable false-positive rates. Most misses are small, far balls.
- Run-to-run variation: a control retrain with seed 7 gave 100/110, 93/77, 86/38 and 76/12 at the four thresholds. That is 7 to 17 more false positives at 0.25 to 0.45 and 5 fewer true positives at 0.55. Treat differences of this size as noise.
- Speed: the author's README reports about 30 Hz on an iPhone for the whole on-device stack (ball detector with person detection and pose). The detector alone was not timed.
- Core ML accuracy: not measured. The figures above are for the PyTorch weights.
Fine-tuned vs stock YOLO26
The point of fine-tuning, measured on the same independent test split of the public dataset (396 frames, 219 balls, 149 of them 16 px or smaller; heads blurred). Stock YOLO26s is the COCO-pretrained model, keeping only the COCO class "sports ball" (class 32); box2boxcam v1.0 is the fine-tuned detector. Same tool (scripts/evaluate_detector.py), 960 px input, IoU >= 0.5, true / false positives per confidence threshold.
| Model | 0.25 | 0.35 | 0.45 | 0.55 | Recall / precision at 0.25 | Small balls found at 0.25 | Max TP at FP <= 25 / 60 / 100 / 200 |
|---|---|---|---|---|---|---|---|
| Stock YOLO26s (COCO "sports ball") | 51 / 55 | 47 / 22 | 35 / 9 | 27 / 4 | 23 % / 48 % | 23 of 149 | 47 / 53 / 65 / 72 |
| Before automatic field labels | 96 / 207 | 93 / 113 | 88 / 61 | 81 / 18 | 44 % / 32 % | 54 of 149 | 85 / 88 / 92 / 96 |
| box2boxcam v1.0 | 99 / 100 | 92 / 52 | 85 / 22 | 82 / 4 | 45 % / 50 % | 55 of 149 | 86 / 93 / 99 / 111 |
Stock YOLO26s does find some balls: 51 of the 219 at confidence 0.25 (86 even at its lowest threshold of 0.05, with 536 false boxes), but it misses most of the small, far balls that matter on a sideline phone video. Fine-tuning roughly doubles the balls found at every threshold (99 against 51 at 0.25) and finds 55 of the 149 small balls against 23. A paired bootstrap over frames (2000 resamples, fine-tuned minus stock) gives +48 true positives at 0.25 (95 % interval +36 to +61), +55 at 0.55 (+41 to +69, with no change in false positives), and +34 to +40 true positives at every false-positive budget of 25 to 200 (all intervals exclude zero). Blurring heads barely matters: on the same frames unblurred, the fine-tuned model scores 100 / 103, 93 / 60, 86 / 30 and 81 / 3, and the stock model 56 / 57, 46 / 24, 35 / 11 and 27 / 3.

Precision against recall over all confidence thresholds on the test split. Circles mark confidence 0.25, squares 0.55.

Training curves of the released model (30 epochs): box and class loss on the training and validation sets, and validation mAP50 and mAP50-95 per epoch. The validation set is the one used during training (it shares its match with the training set), not the independent test split above.
What did not help
Full write-up: negative results.
- WASB published ball weights: almost no extra balls at a usable false-positive level.
- 3-frame (9-channel) stacking: no gain beyond noise, about 3x GPU time.
- Gated low-threshold re-detection: +1 to +6 hits per recording, no net gain.
- Copy-paste of small balls into training images: no gain.
- A mosaic and reduced-scale recipe that looked like a precision gain did not replicate with another seed.
Licence
This model is licensed AGPL-3.0 because it is trained with Ultralytics YOLO, whose licence covers the models it produces. Distributing these weights, or an app that contains them, means releasing the corresponding source under AGPL-3.0; closed-source apps need a commercial Ultralytics (Enterprise) licence, according to Ultralytics. Not legal advice.
Citation
@misc{box2boxcam2026,
title = {box2boxcam: football ball detection for amateur matches},
author = {Thibault Gillard},
year = {2026},
howpublished = {\url{https://github.com/Thibault-GILLARD/box2boxcam-football-vision}}
}
The box2boxcam project
box2boxcam turns an iPhone on a motorised gimbal into an automatic cameraman for amateur football. Everything is open, so take what is useful:
- Ball detector (YOLO26 + Core ML): you are here
- Ball detection dataset: datasets/Totorotibo84/box2boxcam-football-ball-detection-dataset
- Code, benchmark and write-up: Thibault-GILLARD/box2boxcam-football-vision
If you use any of it, a star, a like or a short message about what you built is very welcome, and so are issues and pull requests.
Acknowledgements
- Ultralytics: YOLO26 base model and training framework.
- SoccerTrack v2 (Scott et al., arXiv:2508.01802, CC BY 4.0): used only for the camera-guidance benchmark, not for training.