In this project we used fine-tuning of a YOLOv7 network and implementation and training of a BYOL network to classify, localise and split into teams, players and other objects in football games.
Draws inspiration from a similar basketball-based implementation by James Skelton - https://blog.paperspace.com/yolov7/
In this notebook, we will explain and implement the algorithm.
We can divide the workflow into 2 main steps:
- Localisation and Classification of football match image or video.
- Clustering of players from image to their two teams.
Combining the results from these steps should yield the desired result. The workflow can be depicted as follows:

| Library | Version |
|---|---|
Python |
3.8 |
cuda (for GPU usage) |
11.6 |
(for example)
python3 -m venv venv
source venv/bin/activatepip install -r requirements.txtDownload the weights for each of the networks, they're stored here: https://drive.google.com/drive/folders/1rpshi_ZycbRSJtwy1QXx73oTUWTzcJgk?usp=sharing
Open a terminal inside the cloned repo and run the following:
python run.py --yolo-weights 'path/to/YOLO/weights.pt' --byol-weights 'path/to/BYOL/weights.pt' --source 'path/to/source/image_or_video'- yolo-weights = pretrained weights for YOLO network
- byol-weights = pretrained weights for BYOL network
- source = path to source image or video
- img-size = inference size in pixels (default=640)
- conf-thres = object confidence threshold (default=0.25)
- iou-thres = IOU threshold for NMS (default=0.45)
- device = cuda device, i.e. 0 or 0,1,2,3 or cpu (default='')
- view-img = display results
- save-txt = save results to *.txt
- save-conf = save confidences in --save-txt labels
- nosave = do not save images/videos
- classes = filter by class: --class 0, or --class 0 2 3 (0:ball, 1:goalkeeper, 2:player, 3:referee)
- agnostic-nms = class-agnostic NMS
- augment = augmented inference
- project = save results to project/name (default='detections')
- name = save results to project/name (default='run')
- exist-ok = existing project/name ok, do not increment
- no-trace = don`t trace model
| File name | Purpose |
|---|---|
Readme.md |
Explanation of repo contents and how to use them |
requirements.txt |
Requirements file for all the algorithms |
yolov7-main |
Directory of YOLOv7 codebase |
byol-main.py |
BYOL codebase |
run.py |
Run end to end detect algorithm. |
Other |
Directory with all other code we used during training |
[1] Official YOLOv7 - Implementation of paper - https://github.com/WongKinYiu/yolov7
[2] Paperspace Blog "How to train and use a custom YOLOv7 model" - https://blog.paperspace.com/yolov7/
[3] BYOL - Technion DL Tutorial - Tal Daniel - https://github.com/taldatech/ee046211-deep-learning/blob/main/ee046211_tutorial_09_self_supervised_representation_learning.ipynb
