This project performs player detection and re-identification in a 15-second soccer video using a fine-tuned YOLOv11 model and Deep SORT tracker enhanced with the osnet_ain_x1_0 appearance model from TorchreID.
Players are tracked even when they leave and re-enter the frame, and the same IDs are consistently assigned throughout the clip.
- Uses YOLOv11 for real-time object detection (players, ball, etc.)
- Integrates Deep SORT for multi-object tracking with re-identification
- Embeds appearance features using TorchreID (osnet_ain_x1_0)
- Filters out non-player detections and maintains track ID consistency
- Outputs annotated video with tracked player IDs
Ensure soccer_player_reidentify.py, best.pt (YOLOv11 model), and your video file (e.g., 15sec_input_720p.mp4) are in the same directory.
python3 -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activatepip install -U pip
pip install ultralytics
pip install opencv-python
pip install torch torchvision torchaudio
pip install torchreid
pip install deep_sort_realtimeNote: TorchReID may require specific PyTorch versions. You can install it manually from source if needed:
pip uninstall torchreid
git clone https://github.com/KaiyangZhou/deep-person-reid.git
cd deep-person-reid
pip install -e .Make sure the following files are in your working directory:
- soccer_player_reidentify.py — Main script
- best.pt — Trained YOLOv11 weights (fine-tuned on player & ball classes)
- 15sec_input_720p.mp4 — Input video
Then, run the script:
python soccer_player_reidentify.pyThis will:
- Open the video
- Detect players using YOLOv11
- Track each player using Deep SORT
- Assign persistent IDs
- Write an output video file named output.mp4
You can view the results in real-time or press q to stop early.
- output.mp4: A new video file with bounding boxes and consistent Player {ID} labels.
- Players that re-enter the frame are given their original ID (re-identification).
- Only players are visualized (referees, ball, or other classes are filtered out).
- Python 3.8–3.11 recommended
- GPU support (CUDA) is optional but recommended for performance
- Tested on macOS and Linux; Windows supported with slight path adjustments
For questions or improvements, feel free to reach out.