YOLOv8n · Transfer Learning · Fine-tuned

Model Insights

A YOLOv8 nano model fine-tuned on ~4 300 basketball images from Roboflow. Trained for 50 epochs on an NVIDIA L4 GPU in Google Colab Pro with transfer learning from ImageNet weights.

Performance Metrics

mAP50
80%

Mean average precision at IoU threshold 0.5, the main detection metric

Precision
84%

Of all predicted bounding boxes, how many were actually correct

Recall
71%

Of all real balls in the dataset, how many did the model find

mAP50-95
55%

mAP averaged across IoU thresholds from 0.5 to 0.95, a stricter measure

Training Curves

mAP500.803
mAP50–950.553
Precision0.842
Recall0.705
Box Loss ↓0.48

mAP50, Precision, Recall and Box Loss over 50 epochs. The model improved continuously. Early stopping was never triggered.

Confusion Matrix

Confusion Matrix

Basketball
Background
← True label →
Basketball
1422
TP
Correctly detected balls
423
FP
Background mistaken for ball
Background
480
FN
Missed balls
0
TN
Background ignored
↑ Predicted label ↓

True positives vs false positives/negatives at the default confidence threshold.

Training Details

Model
YOLOv8n
Base weights
yolov8n.pt (ImageNet)
Epochs
50
Batch size
16
Image size
640 × 640 px
Optimizer
AdamW
Learning rate
0.002
Momentum
0.9
Early stopping
patience=10 (not triggered)
Training time
~18 min (0.303 h)
GPU
NVIDIA L4 (Colab Pro)
Inference speed
0.5 ms / frame
Model size
6.2 MB
Parameters
3 005 843

Dataset

Dataset name
Basketball-ball-detection
Source
Roboflow
Total images
~4 300
Train images
3 154
Val images
789
Classes
1 — Basketball

The original dataset had no train split, so an 80/20 split was created automatically from the validation set and the data.yaml was updated accordingly.

Architecture

YOLOv8n is the nano variant of Ultralytics' YOLOv8 family, the smallest and fastest model, ideal for single-class detection tasks like basketball tracking.

The backbone extracts multi-scale features using a CSP (Cross Stage Partial) structure. The neck uses a PANet to fuse features across scales. The detection head predicts bounding boxes and class probabilities in a single forward pass.

Transfer learning: instead of training from scratch, we start from weights pre-trained on ImageNet. The model already knows how to detect edges, shapes, and textures, so we only need to fine-tune it to recognise a basketball specifically.

Why nano? 6.2 MB, 3M parameters, 0.5 ms inference. More than enough for one class on a clear camera angle.

Commentary Voice

ElevenLabs powers the AI commentator. When tracking completes, the backend calls the ElevenLabs text-to-speech API and streams the audio back to the browser.

Model: eleven_multilingual_v2, chosen for its natural pacing and expressiveness at low stability settings.

Voice settings: stability 0.3 (more dynamic, less monotone) · similarity boost 0.85 (stays close to the original voice character).

Script structure: each trail color has its own script. Every script starts with "And THERE it is", drops the user's name, mentions the model accuracy, then closes with a ByteTrack line and a punchline. Crowd audio plays underneath and fades when both the video and commentary are done.

Reflections

What worked well: The model reliably detects the ball in clear shots and the neon trail makes the tracking visually compelling. The 80/20 auto-split workaround for the missing train set is a practical technique worth knowing.

Challenges: Fast motion blur and occlusion (players blocking the ball) are the main weak points. The confidence threshold had a big impact: too low caused false positives on players' feet, too high missed real detections.

I didn't expect transfer learning to work this well on a small dataset. The model picked it up fast because it already knew what shapes and edges look like from being trained on millions of other images. The biggest surprise was how straightforward YOLO actually was to work with. I expected a lot more complexity, but getting it to detect the ball only took a few lines of code once the model was trained. I also learned that the confidence setting matters a lot. If it's too low the model starts detecting things that aren't the ball, if it's too high it misses the ball when things get messy. The thing that took the most time was actually building the app around the model. Training took 18 minutes but getting everything to work together as a real product took way longer than that.