This document outlines the setup and steps required to preprocess soccer match videos by removing unwanted segments, extracting relevant frames, and preparing data for model training
-
Create a Conda Environment
Start by creating a new Conda environment namedsoccer-preprocess
with Python 3.11 installed.conda create -n soccer-preprocess python=3.11 -y
Activate the environment:
conda activate soccer-preprocess
-
Install PyTorch
Install PyTorch, torchvision, torchaudio, and the corresponding CUDA toolkit version (e.g., for CUDA 11.7) using the commands below. Adjust the CUDA version based on your system's specifications.conda install pytorch==2.0.1 torchvision==0.15.2 torchaudio==2.0.2 pytorch-cuda=11.7 -c pytorch -c nvidia
For different CUDA versions, refer to PyTorch's previous versions for guidance.
-
Additional Dependencies
Install other necessary Python packages:pip install ultralytics supervision moviepy scikit-learn
-
Trim Videos
Remove pre-match programs and halftime advertisements by keeping only the match segments. For example, if the match is from 00:15:00 to 00:50:00 and 01:05:00 to 01:40:00, these segments are retained:python trim_videos.py /path/to/your/video.mp4 00:15:00-00:50:00 01:05:00-01:40:00
Alternatively, you can use video editing software for this step. Store the trimmed videos in the
initial-trimmed-videos
directory. -
Extract Frames
To extract frames from the videos, adjust theVIDEO_DIR_PATH
andIMAGES_DIR_PATH
inget_video_frames.py
and run:python get_video_frames.py
This saves every 300th frame, producing approximately 2000 images (~1000 images per video).
-
Organize Frames
Manually categorize the frames into relevant and irrelevant folders within aData
directory. Typically, use around 650 irrelevant frames and 950 relevant frames.
-
Prepare Training Data
Update the paths inprepare_training_data.py
and execute it to split the data into training, testing, and validation sets. -
Model Training
Navigate to the "Model Training" directory and initiate the training process:cd "Model Training" python train.py
-
Remove Irrelevant Frames
Inside theRemove Irrelevant Frames
directory, adjust the paths inscript.py
and run it to segregate videos into relevant and irrelevant frames. -
Remove Replays
Manually record replay timestamps in text files (seeReplay Timestamps
folder for examples). Execute the following command to remove replays from videos:python remove_replays.py input_video_path output_video_path timestamps_file_path
This guide provides a comprehensive walkthrough for preprocessing soccer match videos, from environment setup to data preparation and model training. Follow each step carefully to ensure the successful completion of the process.