A computer vision system that uses Vision Language Models (VLMs) and unsupervised clustering to classify people in basketball footage as Team A, Team B, and referees.
The system uses SigLIP and K-Means clustering to classify players on a basketball court into:
- Team A (displayed in blue)
- Team B (displayed in red)
- Referees (displayed in yellow)
Summary of how the system works:
- Detects people with YOLO object detection
- Filters out audience members and coaches on the sideline
- Extracts embeddings with SigLIP
- Clusters embeddings to identify teams and referees
- Classifies players and referees
- Python 3.10 or higher
- A video of basketball gameplay
- GPU
-
Clone the repository
-
Create a virtual environment
python -m venv venv source venv/bin/activate -
Install dependencies
pip install -r ../requirements.txt
-
Download YOLO weights (
yolov8n.ptwill automatically be downloaded on the first execution.)
-
Put your video file in the
vlm_team_classifierdirectory -
Edit the video path in
run_video.pyif __name__ == "__main__": main("warriors_bucks.mp4") # Change to your video's filename
-
Run this script:
python run_video.py
-
Initialization:
- The script loads YOLO
- Loads the SigLIP model
- Searches for a frame with at least 9 people on the court
-
Training:
- Once a frame is found, embeddings are extracted from all detected people
- Groups people into 3 clusters (Team A, Team B, Referees) with K-Means clustering
- The smallest cluster is assigned as the referees
-
Classification:
- Processes each frame
- Detects people with YOLO
- Classifies each person as Team A, Team B, or Referee
- Adds colored outlines over video to display classifications
- Press Q to quit
- The video must show basketball gameplay
- At least one frame must have at least 9 people on the court
A real-time video window showing:
- Color coded bounding boxes around each detected person on the court
- Classification labels on top of each box
For running the simpler baseline classifier:
python run_baseline.pyThis only uses average jersey colors.