SwishAI is a Computer Vision application designed to analyze basketball shots from video footage automatically. Powered by YOLOv11 and a modern React + FastAPI stack, it tracks players, basketballs, and hoops in real-time, calculating shooting percentage and visualizing successful shots with dynamic overlays.
If you find SwishAI useful, please consider supporting the development! π
- Key Features
- Screenshots
- Usage Guide
- Tech Stack
- Project Architecture
- Installation & Setup
- Technical Logic & AI
- Model Training & Performance
- Credits
- License
- Advanced Object Detection: Detects 5 distinct classes: Ball, Ball in Basket, Player, Basket, and Player Shooting.
- Smart Scoring System: Automatically counts shots attempted vs. made to calculate real-time Field Goal Percentage (FG%).
- Visual FX: Renders dynamic "pulse" animations and overlays when a basket is scored.
- Configurable AI: Users can adjust Confidence Thresholds for each class via the UI to adapt to different lighting conditions.
- Processing Modes - the video can be processed with 3 different modes:
- Full Tracking: Bounding boxes + Visual Effects + HUD.
- Stats & Effects: Clean view with only scoring effects and HUD.
- Stats Only: Minimalist overlay.
- Performance Optimization: Includes a "Test Mode" (processes only the first 15s) and auto-cleanup mechanisms to manage server storage.
Watch a full demonstration of SwishAI in action:
- Open the App: Go to the local frontend URL.
- Upload Video: Click the upload area to select a basketball video (MP4, MOV, AVI).
- Configure Settings (Optional):
- Processing Mode: Choose between Full Tracking, Stats & Effects or Stats Only.
- Advanced Settings: Click "Advanced" to tweak confidence thresholds for specific classes (e.g., lower "Ball" threshold for dark videos).
- Test Mode: Check "Test Mode" to process only the first 15 seconds. Useful to check if the model works properly.
- Start Analysis: Click the Start Analysis button. You will see a real-time progress bar and stats updating as the backend processes the video.
- Download: Once complete, download the rendered video with overlays.
- YOLOv11s (Ultralytics): Latest SOTA object detection model
- PyTorch: Deep learning framework
- OpenCV (cv2): Video processing and drawing logic
- NumPy: Matrix operations for game logic
- FastAPI: High-performance, asynchronous Python web framework
- Uvicorn: ASGI server implementation
- Threading: Background video processing handling
- React 18: UI Library
- Vite: Next-generation frontend tooling
- Tailwind CSS: Utility-first CSS framework for styling
- Lucide React: Modern icon set
SwishAI/
βββ BE/ # Backend (Python)
β βββ basketball_training/ # Training scripts & artifacts
β β βββ weights/ # Stores best.pt after training
β β βββ data_basketball.yaml # Dataset configuration
β βββ processed/ # Output videos (Auto-cleaned)
β βββ uploads/ # Raw user uploads (Auto-cleaned)
β βββ app.py # FastAPI Server & Business Logic
β βββ train_model.py # YOLO Training Script
β βββ requirements.txt # Python dependencies
βββ FE/ # Frontend (React)
β βββ src/ # Source code
β β βββ App.jsx # Main UI Component
β βββ public/ # Static assets
β βββ tailwind.config.js # Tailwind configuration
β βββ package.json # Node dependencies
βββ README.md
- Python 3.10+
- Node.js 18+ & npm
- NVIDIA GPU (Optional but highly recommended for training/inference)
Navigate to the backend directory:
cd BECreate and activate a virtual environment:
python -m venv venv
# Windows:
.\venv\Scripts\activate
# Mac/Linux:
source venv/bin/activateInstall dependencies:
pip install -r requirements.txtStart the API server:
python app.pyServer will run at http://localhost:8000.
Navigate to the frontend directory:
cd FEInstall packages:
npm installStart the development server:
npm run devClient will run at http://localhost:5173.
Before running the app, you need to train the model (or use pre-trained weights).
Download Dataset: Get the basketball detection dataset from Roboflow Universe.
Configure Training:
- Ensure the dataset is extracted into
BE/basketball-detection-srfkd-1 - Check
train_model.pyconfig class (the script is tailored for my hardware: GTX 1060 6GB - i7 6700k - 16gb ram):
DATASET_DIR = Path("basketball-detection-srfkd-1")
EPOCHS = 200
BATCH_SIZE = 8 # Adjust based on your VRAMRun Training:
cd BE
python train_model.pyThis script handles auto-validation, GPU checks, and custom augmentation.
To prevent double-counting, the system implements physics-based cooldown logic (app.py):
- Shot Cooldown (1.5s): Prevents the model from registering multiple shots for a single throwing motion.
- Basket Cooldown (2.0s): Ensures the ball swishing through the net isn't counted twice in consecutive frames.
The training script (train_model.py) uses specialized augmentation for sports footage:
- HSV Saturation (0.7): Helps detect orange balls in varied lighting.
- Shear (2.0Β°): Improves robustness against camera angles.
- Mixup (0.15): Helps separating players in crowded scenes.
| ID | Class Name | Default Confidence |
|---|---|---|
| 0 | Ball | 0.60 |
| 1 | Ball in Basket | 0.25 |
| 2 | Player | 0.70 |
| 3 | Basket | 0.70 |
| 4 | Player Shooting | 0.77 |
SwishAI uses a custom-trained YOLOv11s model trained on the Basketball Detection Dataset from Roboflow Universe.
- Dataset Source: Roboflow Universe - Basketball Detection
- Dataset Size: ~10,000 annotated images
- License: CC BY 4.0
- Classes: 5 (Ball, Ball in Basket, Player, Basket, Player Shooting)
- Training Date: March 17, 2025
The model was trained using a custom training script (train_model.py) specifically optimized for consumer-grade hardware:
Hardware Specifications:
- GPU: NVIDIA GTX 1060 6GB
- CPU: Intel i7-6700K
- RAM: 16GB DDR4
- Training Duration: ~48 hours continuous
Training Parameters:
- Model: YOLOv11s (small variant for efficiency)
- Epochs: 200
- Batch Size: 8 (optimized for 6GB VRAM)
- Image Size: 640x640
- Optimizer: AdamW
- Learning Rate: 0.001 (with cosine decay)
Key Performance Indicators (Final Model - Epoch 200):
- mAP50: 0.909 (Mean Average Precision at IoU 0.5)
- mAP50-95: 0.623 (Mean Average Precision from IoU 0.5 to 0.95)
- Overall Precision: 0.878
- Overall Recall: 0.861
Per-Class Performance:
| Class | Precision | Recall | mAP50 |
|---|---|---|---|
| Ball | 0.80 | 0.88 | 0.847 |
| Ball in Basket | 0.51 | 0.36 | 0.932 |
| Player | 0.86 | 0.85 | 0.928 |
| Basket | 0.91 | 0.91 | 0.966 |
| Player Shooting | 0.76 | 0.34 | 0.873 |
The train_model.py script includes:
- Hardware-specific optimizations for GTX 1060 6GB (batch size, workers, memory management)
- Custom augmentation pipeline tailored for basketball footage (HSV saturation, shear, mixup)
- Automatic validation split (80/20 train/val)
- Early stopping and checkpoint saving
- Mixed precision training (FP16) for faster training on lied VRAM
Note on Model Improvement: The current model achieves strong performance for real-time basketball analysis. However, further improvements are possible through:
- Extended training (300+ epochs)
- Larger model variants (YOLOv11m or YOLOv11l)
- Additional data augmentation techniques
- Fine-tuning on specific court environments
- Ensemble methods or model fusion
Users with more powerful hardware (RTX 3080+, 24GB+ VRAM) can modify the training parameters in
train_model.pyto achieve higher accuracy.
- Developer: sPappalard
- Dataset: Roboflow Universe - Basketball Detection
- Frameworks: Ultralytics YOLO, FastAPI, React
@misc{
basketball-detection-srfkd_dataset,
title = { Basketball detection Dataset },
type = { Open Source Dataset },
author = { basketball },
howpublished = { \url{ https://universe.roboflow.com/basketball-6vyfz/basketball-detection-srfkd } },
url = { https://universe.roboflow.com/basketball-6vyfz/basketball-detection-srfkd },
journal = { Roboflow Universe },
publisher = { Roboflow },
year = { 2025 },
month = { mar },
note = { visited on 2025-11-30 },
}This project is released under the GNU Affero General Public License v3.0 (AGPL-3.0).
Why AGPL-3.0? This project integrates Ultralytics YOLO, which is licensed under AGPL-3.0. As a derivative work, RotoAI inherits this license to ensure full compliance with the open-source terms of its dependencies.
What this means for you:
- β Use: You can use this software for personal, research, or commercial purposes.
- β Modify: You can modify the source code.
- π Share: If you distribute this software or host it as a network service (SaaS), you must disclose the source code of your modified version under the same AGPL-3.0 license.
Copyright (c) 2025 sPappalard.













