This repository uses Git submodules for the ML Manager. You must clone it correctly:
# Clone with submodules (RECOMMENDED)
git clone --recursive https://github.com/masouduut94/volleyball_analytics.git
# OR if already cloned, initialize submodules
git submodule update --init --recursive- ๐ ML Pipeline: Video classification + Object detection for volleyball analysis
- ๐ฎ Game State Classification: Service, Play, No-Play detection using VideoMAE
- ๐ญ Action Detection: 6 volleyball actions (serve, receive, set, spike, block, ball)
- ๐๏ธ Court Segmentation: Court boundary detection
- ๐ Analytics: Real-time statistics and insights
- ๐ API Backend: FastAPI-based backend for data storage and retrieval
This machine learning project runs in real-time on top of 2 deep learning models:
In a live broadcast game, it's important to run processes only when the game is on. To extract the periods when the game is active, HuggingFace VideoMAE is utilized.
๐ฏ Purpose: Game state classification with 3 labels
- ๐ SERVICE: Start of play when a player tosses the ball to serve
- ๐ฎ PLAY: Active game periods where players are playing
- โธ๏ธ NO-PLAY: Inactive periods where players are not playing
This state-of-the-art model is trained on a custom volleyball dataset for object detection and action recognition.
๐จ Detection Classes (6 different objects with color-coded bounding boxes):
- ๐ด Red box: Volleyball ball
- ๐ค Brown box: Volleyball service action
- ๐ข Green box: Volleyball reception action
- ๐ต Blue box: Volleyball setting action
- ๐ฃ Purple box: Volleyball blocking action
- ๐ Orange box: Volleyball spike action
The system provides real-time analysis with:
- ๐ฎ Game State: Displayed in top-left corner (SERVICE/PLAY/NO-PLAY)
- ๐ฏ Object Detection: Color-coded bounding boxes (only on SERVICE and PLAY frames)
- ๐ Analytics: Real-time statistics and insights
The system can extract specific game moments, like ace points:

- ๐ Python: 3.11 or higher
- ๐พ PostgreSQL: For database functionality (optional)
- ๐ฎ GPU: Recommended for real-time inference (CUDA compatible)
-
Clone with Submodules
git clone --recursive https://github.com/masouduut94/volleyball_analytics.git cd volleyball_analytics -
Install Dependencies
# Using uv (recommended) uv sync # Or using pip with pyproject.toml pip install -e . # Or using pip with dependencies from pyproject.toml pip install torch torchvision ultralytics transformers opencv-python pillow numpy
-
Fix PyTorchVideo Compatibility (โก IMPORTANT!)
# Uninstall old pytorchvideo to avoid compatibility issues pip uninstall pytorchvideo -y # Install latest version from GitHub (fixes torchvision compatibility) pip install git+https://github.com/facebookresearch/pytorchvideo
-
Download Model Weights
# Create weights directory mkdir -p weights # Download weights (see Weights section below)
The system requires pre-trained models for inference. Weights are automatically downloaded when you first run the system, or you can download them manually.
from ml_manager import MLManager
# Weights are automatically downloaded if missing
manager = MLManager()from ml_manager.utils.downloader import download_all_models
# Download all models in one ZIP file
success = download_all_models()weights/
โโโ ๐ ball/weights/best.pt # Ball detection & segmentation
โโโ ๐ญ action/weights/best.pt # Action detection (6 classes)
โโโ ๐๏ธ court/weights/best.pt # Court segmentation
โโโ ๐ฎ game_state/ # Game state classification
โโโ [checkpoint files]
Download Source: Complete Weights ZIP
Use our comprehensive test script to validate the ML Manager with your video:
# Run complete test with your video
python test_ml_manager.py --video_path path/to/your/video.mp4
# Test only object detection
python test_ml_manager.py --video_path path/to/your/video.mp4 --mode detection
# Test only video classification
python test_ml_manager.py --video_path path/to/your/video.mp4 --mode classification
# Custom output directory
python test_ml_manager.py --video_path path/to/your/video.mp4 --output_dir my_results/For testing the ML models, download a volleyball video clip from this YouTube video (starts at 3:13). This video contains excellent examples of volleyball actions and game states for testing.
Why this video is perfect for testing:
- ๐ Clear volleyball actions (serve, spike, block, set)
- ๐ฎ Multiple game states (service, play, no-play)
- ๐น Good video quality and camera angles
- โฑ๏ธ Multiple rallies and game situations
How to use:
- Download the video using any YouTube downloader
- Save it as
volleyball_test.mp4(or any name you prefer) - Run the test script:
python test_ml_manager.py --video_path volleyball_test.mp4
Test specific components individually:
# Basic inference test using demo.py
python src/demo.py --video_path path/to/your/video.mp4
# VideoMAE only (game state classification)
python src/VideoMAE_inference.py
# YOLO only (object detection)
python src/yolo_inference.pyThe system uses a unified ML Manager module for all machine learning operations:
from src.ml_manager import MLManager
# Initialize ML Manager
ml_manager = MLManager(verbose=True)
# Game state classification
game_state = ml_manager.classify_game_state(frames)
# Action detection
actions = ml_manager.detect_actions(frame)
# Ball detection
ball_detections = ml_manager.detect_ball(frame)๐ ML Manager Documentation: See src/ml_manager/README.md for comprehensive usage.
The test_ml_manager.py script provides comprehensive testing of all ML Manager functionality:
๐ What the test script does:
- โ Validates video file format and properties
- โ Tests ML Manager initialization and model loading
- โ Verifies all detection models (ball, actions, players)
- โ Tests game state classification with video sequences
- โ Runs full pipeline demos with visualization
- โ Generates output videos for verification
๐ Test modes available:
full: Complete testing with both detection and classification demosdetection: Object detection testing only (ball, actions, players)classification: Video classification testing only (game states)
# Comprehensive test (recommended for first-time setup)
python test_ml_manager.py --video_path path/to/volleyball_video.mp4
# Quick model validation (no video output)
python test_ml_manager.py --video_path path/to/volleyball_video.mp4 --mode detection
# Legacy testing methods
cd src/ml_manager
python test_ml_manager.py
# Test integration
cd ../..
python src/ml_manager/example_usage.pyFor storing results and analytics, set up PostgreSQL:
Follow the PostgreSQL installation guide
# Create database config
cp conf/sample.env conf/.env
# Edit conf/.env with your database credentials
MODE=development
DEV_USERNAME=your_username
DEV_PASSWORD=your_password
DEV_HOST=localhost
DEV_DB=volleyball_development
DEV_PORT=5432
DEV_DRIVER=postgresql
TEST_DB_URL=sqlite:///./vb.db# Start the API server
uvicorn src.backend.app.app:app --reload
# In another terminal, seed the database
python src/api_init_data.py
# Run the main pipeline
python src/main.pyThe video clips used for training and testing are sourced from:
- ๐บ YouTube Channel: Volleyball Watchdog
- ๐ Content: International volleyball matches and tournaments
-
๐ Data Analysis: Advanced KPIs and analytics
- Service success rate analysis
- Service zone analysis
- Reception success rate
- Player performance metrics
- Team strategy analysis
-
๐ Dataset Publication: Open-source datasets
- Video classification dataset
- Volleyball object detection dataset
- Annotated training data
-
๐ฏ Real-time Analytics: Live match analysis
- Real-time statistics
- Live performance metrics
- Instant insights for coaches
volleyball_analytics/
โโโ ๐ง src/ # Main source code
โ โโโ ๐ฎ ml_manager/ # ML Manager submodule
โ โโโ ๐ backend/ # FastAPI backend
โ โโโ ๐ฌ main.py # Main ML pipeline
โ โโโ ๐ฅ demo.py # Demo application
โ โโโ ๐ ๏ธ utilities/ # Utility functions
โโโ ๐ data/ # Datasets and processed data
โโโ ๐ฏ weights/ # Model weights (download required)
โโโ ๐ notebooks/ # Jupyter notebooks
โโโ ๐ ๏ธ scripts/ # Utility scripts
โโโ ๐ conf/ # Configuration files
โโโ ๐ README.md # This file
-
๐ซ Import Errors
# Ensure submodules are initialized git submodule update --init --recursive # Check Python path python -c "from src.ml_manager import MLManager; print('Success!')"
-
๐ฏ Model Weights Missing
- Verify weights directory structure
- Check download links above
- Ensure file permissions are correct
-
๐ Dependencies Issues
# Reinstall dependencies uv sync --reinstall # Or using pip pip install -e . # Or reinstall specific packages pip install torch torchvision ultralytics transformers pytorchvideo opencv-python pillow numpy
-
๐ฏ PyTorchVideo Compatibility Error (โก EASIEST SOLUTION)
ModuleNotFoundError: No module named 'torchvision.transforms.functional_tensor'๐ก Quick Fix (Recommended):
# Uninstall old pytorchvideo pip uninstall pytorchvideo -y # Install latest version from GitHub (fixes compatibility) pip install git+https://github.com/facebookresearch/pytorchvideo
๐ Alternative Manual Fix: If you encounter this error in your own code, replace:
import torchvision.transforms.functional_tensor as F_t
with:
import torchvision.transforms.functional as F_t
-
๐พ Database Connection
- Verify PostgreSQL is running
- Check
.envfile configuration - Ensure database exists and is accessible
- ๐ Fork the repository
- ๐ฟ Create a feature branch
- ๐ป Make your changes
- ๐งช Add tests if applicable
- ๐ Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
- ๐ Wiki: Datasets and Weights
- ๐ API Documentation: API Guide
- ๐ฎ ML Manager: Comprehensive Documentation
- ๐ Examples: Usage Examples
๐ Happy Volleyball Analytics! Let's revolutionize the game with AI! ๐โจ





