Downloads · 30 days
12
17% of all-time downloads
rarfileexe/Football-Referee-Card-Detector
Football-Referee-Card-Detector is a object detection model from rarfileexe. Use it when you need objects located in an image. It is set up for ultralytics. The card lists the license as agpl-3.0.
A YOLOv8m model fine-tuned to detect referee cards (Green, Red, and Yellow) in football/soccer match footage. Trained on a custom dataset built from scratch — no prior dataset existed for this specific task.
Downloads · 30 days
12
17% of all-time downloads
All-time downloads
70
Public
Repo size
52 MB
Likes
0
Public
Click a slice to open those files.
.pt52 MB · 100%
From the Hugging Face model README
A YOLOv8m model fine-tuned to detect referee cards (Green, Red, and Yellow) in football/soccer match footage. Trained on a custom dataset built from scratch — no prior dataset existed for this specific task.
This model was developed as part of a larger computer vision pipeline for football match analysis, which included player face recognition (FaceNet + MTCNN + DBSCAN) and emotion detection (DeepFace). Card detection was the hardest component: no existing dataset or off-the-shelf solution was found, so the dataset was curated, annotated, and trained entirely from the ground up.
| Property | Value |
|---|---|
| Architecture | YOLOv8m (Ultralytics) |
| Task | Object Detection |
| Input Size | 640 × 640 px |
| Classes | 3 (Green Card, Red Card, Yellow Card) |
| Optimizer | AdamW |
| Epochs | 150 (early stopping patience: 30) |
| Batch Size | 16 |
| Confidence Threshold | 0.5 (recommended) |
| Training Platform | Kaggle (GPU) |
| Framework | Ultralytics YOLOv8 |
| ID | Class | Description |
|---|---|---|
| 0 | Green Card | Rarely issued; used in some competitions for temporary suspensions |
| 1 | Red Card | Player dismissal |
| 2 | Yellow Card | Caution / warning |
Note on Green Cards: Green cards are uncommon in mainstream football but appear in some competitions (e.g. Serie A's fair play experiments, youth football). Including this class makes the model more broadly applicable across different football contexts.
| Split | Images | Annotations |
|---|---|---|
| Train | 390 | 399 |
| Validation | 33 | ~34 |
| Total | 423 | ~433 |
Source images (pre-augmentation): ~141 unique images collected via Google Images search.
Augmentation applied per source image (3× expansion):
Annotation class distribution (train split):
The dataset was labelled and managed using Roboflow and is publicly available under CC BY 4.0: 👉 Card Detection Dataset on Roboflow Universe
pip install ultralytics
from ultralytics import YOLO
model = YOLO("best.pt")
results = model.predict(source="your_image.jpg", conf=0.5)
results[0].show() # display with bounding boxes
from ultralytics import YOLO
model = YOLO("best.pt")
# Video file
results = model.predict(source="match_clip.mp4", conf=0.5, save=True)
# Webcam / live stream
results = model.predict(source=0, conf=0.5, stream=True)
for result in results:
result.show()
from ultralytics import YOLO
model = YOLO("best.pt")
class_names = {0: "Green Card", 1: "Red Card", 2: "Yellow Card"}
results = model.predict(source="your_image.jpg", conf=0.5)
for result in results:
for box in result.boxes:
class_id = int(box.cls)
confidence = float(box.conf)
coords = box.xyxy[0].tolist() # [x1, y1, x2, y2]
print(f"Detected: {class_names[class_id]} | Confidence: {confidence:.2f} | Box: {coords}")
The full training notebook is available in the linked GitHub repository. To reproduce training:
runs/detect/train/weights/best.ptThis model is designed for:
This model was built as part of a proof-of-concept football match analysis system. The full pipeline included:
Card detection was the most challenging component. No existing dataset or pre-built solution was found for detecting referee cards specifically. After over a month of experimenting with classical computer vision approaches (color segmentation, contour detection, shape heuristics), a reliable solution could not be achieved due to lighting variability, card size inconsistency, and partial occlusion in real match footage.
The decision was made to train a custom detection model. The dataset was collected, annotated end-to-end using Roboflow, and the resulting YOLOv8m model achieved reliable real-time detection even under live stream conditions — validating the approach.
If you use this model or dataset in your work, please cite:
@misc{football-card-detector-2025,
title = {Football Referee Card Detector — YOLOv8m},
author = {Hassan},
year = {2025},
publisher = {Hugging Face},
howpublished = {\url{https://huggingface.co/YOUR_USERNAME/football-card-detector}}
}
Model weights: AGPL-3.0 license (As the base weights are from yolo!) Dataset: CC BY 4.0 (via Roboflow Universe)