/Soccer-Player-Re-Identification-using-YOLOv11

Successfully developed a real-time soccer player re-identification and tracking system using YOLOv11 and Deep SORT with TorchreID-based embeddings.

Primary LanguagePythonMIT LicenseMIT

Soccer Player Re-Identification with YOLOv11 and Deep SORT

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.


🧩 Features

  • 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

🔧 Setup Instructions

1. Clone the repository (or place the scripts)

Ensure soccer_player_reidentify.py, best.pt (YOLOv11 model), and your video file (e.g., 15sec_input_720p.mp4) are in the same directory.

2. Create a virtual environment

python3 -m venv venv
source venv/bin/activate   # On Windows: venv\Scripts\activate

3. Install required dependencies

pip install -U pip
pip install ultralytics
pip install opencv-python
pip install torch torchvision torchaudio
pip install torchreid
pip install deep_sort_realtime

Note: 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 .

🚀 Running the Code

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.py

This 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

  • 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).

⚙️ Environment Notes

  • 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

📬 Contact

For questions or improvements, feel free to reach out.