This project implements advanced machine learning models to classify cricket shots into four categories with exceptional accuracy using ensemble learning techniques.
- Best Individual Model: ResNet50V2 (95.24% accuracy)
- Best Ensemble Method: Weighted Averaging (97.14% accuracy)
- Target Achieved: โ 95%+ accuracy goal exceeded
| Model | Accuracy | Method |
|---|---|---|
| Custom CNN | 90.90% | Individual |
| ResNet50V2 | 95.24% | Transfer Learning |
| Advanced CNN | 91.64% | Enhanced Architecture |
| Ensemble (Weighted) | 97.14% | 3-Model Combination |
- Drive: 98% precision, 95% recall
- Legglance-Flick: 96% precision, 96% recall
- Pullshot: 97% precision, 99% recall
- Sweep: 97% precision, 99% recall
shotpredictionml/
โโโ ๐ฏ main.py # Main entry point (EASY TO USE!)
โโโ ๐ ensemble_predictor.py # Core ensemble prediction engine
โโโ ๐ฎ predict.py # Original prediction script
โโโ ๐ quick_ensemble.py # Ensemble evaluation
โโโ ๐ README.md # This file
โโโ ๐ฆ requirements.txt # Dependencies
โโโ ๐ CRICKET_SHOT_CLASSIFICATION_PROJECT.md # Complete documentation
โโโ ๐ saved_models/ # Trained models
โ โโโ ensemble_model_1.keras # Custom CNN (90.90%)
โ โโโ ensemble_model_2.keras # ResNet50V2 (95.24%)
โ โโโ best_advanced_model.h5 # Advanced CNN (91.64%)
โ โโโ advanced_cricket_shot_classifier.h5 # Backup model
โโโ ๐ old_models/ # Previous model versions
โโโ ๐ scripts/ # Additional scripts
โโโ ๐ drive/ # Drive shot images (1,257)
โโโ ๐ legglance-flick/ # Legglance-flick images (1,117)
โโโ ๐ pullshot/ # Pullshot images (1,257)
โโโ ๐ sweep/ # Sweep shot images (1,117)
pip install -r requirements.txt# Single image prediction
python main.py --image drive/drives1.png
# Interactive mode
python main.py --interactive
# Batch prediction (first 5 images)
python main.py --batch drive/# Original prediction script
python predict.py --image path/to/image.jpg
# Ensemble evaluation
python quick_ensemble.py-
Original Classifier (25% accuracy) โ
- Failed due to double preprocessing and over-aggressive augmentation
-
Working Classifier (88% accuracy) โ
- Fixed preprocessing issues with single pipeline
-
Advanced Classifier (91.64% accuracy) โ
- Added Batch Normalization and deeper architecture
-
Ensemble Classifier (97.14% accuracy) ๐
- Combined 3 models using weighted averaging
- Accuracy: 95.34%
- Method: Each model votes, majority wins
- Accuracy: 96.72%
- Method: Average predicted probabilities
- Accuracy: 97.14% ๐
- Method: Weighted average based on individual performance
- Weights: [0.3, 0.4, 0.3] for [Custom CNN, ResNet50V2, Advanced CNN]
- Custom CNN: Sequential CNN with 3 conv blocks
- ResNet50V2: Transfer learning with ImageNet pre-training
- Advanced CNN: Enhanced CNN with Batch Normalization
- Image Size: 224x224 pixels
- Batch Size: 32
- Learning Rate: 0.001 (Adam optimizer)
- Data Augmentation: Rotation, shifts, zoom, brightness
- Callbacks: Early stopping, learning rate reduction, model checkpointing
- Resize: All images to 224x224
- Color Conversion: BGR to RGB
- Normalization: Pixel values scaled to [0,1]
| Model | Architecture | Accuracy | Precision | Recall | F1-Score |
|---|---|---|---|---|---|
| Custom CNN | Sequential CNN | 90.90% | 0.91 | 0.91 | 0.91 |
| ResNet50V2 | Transfer Learning | 95.24% | 0.95 | 0.95 | 0.95 |
| Advanced CNN | Enhanced CNN | 91.64% | 0.92 | 0.92 | 0.92 |
| Ensemble Method | Accuracy | Drive | Legglance-Flick | Pullshot | Sweep |
|---|---|---|---|---|---|
| Hard Voting | 95.34% | 0.95 | 0.94 | 0.96 | 0.96 |
| Soft Averaging | 96.72% | 0.97 | 0.96 | 0.97 | 0.97 |
| Weighted Averaging | 97.14% | 0.98 | 0.96 | 0.97 | 0.97 |
from predict import CricketShotPredictor
# Load the best ensemble model
predictor = CricketShotPredictor('best_advanced_model.h5')
predictor.load_model()
# Predict single image
shot_type, confidence, probabilities = predictor.predict_single_image('image.jpg')
print(f"Predicted: {shot_type} with {confidence:.2%} confidence")# Predict multiple images
results = predictor.predict_batch('folder_with_images/', max_images=50)
for result in results:
print(f"{result['image']}: {result['prediction']} ({result['confidence']:.2%})")# Interactive prediction session
predictor.interactive_predictor()- Ensemble Learning: Combines multiple models for better accuracy
- Transfer Learning: Uses pre-trained ResNet50V2 for feature extraction
- Data Augmentation: Balanced augmentation prevents overfitting
- Batch Normalization: Stabilizes training and improves convergence
- Early Stopping: Prevents overfitting with automatic stopping
- Fixed Double Preprocessing: Single clean data pipeline
- Reduced Augmentation: Conservative augmentation strategy
- Enhanced Architecture: Deeper networks with regularization
- Model Diversity: Different architectures capture different features
- Extract spatial features from cricket shot images
- Translation invariant feature detection
- Hierarchical feature learning
- Use pre-trained models (ResNet50V2) on new tasks
- Faster training and better performance
- Leverage ImageNet features for cricket shots
- Combine multiple models for improved accuracy
- Reduce variance and improve generalization
- Weighted averaging based on individual performance
- Collect more diverse angles and lighting conditions
- Add new shot types (cut, hook, defensive, etc.)
- Include different players and batting styles
- Attention mechanisms for key body parts
- Multi-scale feature extraction
- Temporal information from video frames
- Curriculum learning
- Focal loss for hard examples
- Advanced ensemble methods (stacking, boosting)
- โ Baseline Working: 88.00% accuracy
- โ Advanced Model: 91.64% accuracy
- โ Target Achieved: 97.14% accuracy
- โ Ensemble Success: Weighted averaging method
- Systematic problem diagnosis and solution
- Architecture optimization with Batch Normalization
- Successful transfer learning implementation
- Effective ensemble learning techniques
- Comprehensive error analysis
- Complete Documentation:
CRICKET_SHOT_CLASSIFICATION_PROJECT.md - Model Evolution:
old_models/README.md - Error Analysis:
misclassification_analyzer.py - Prediction Script:
predict.py
- Model Loading: Ensure
.kerasor.h5files are in correct location - Dependencies: Install all requirements with
pip install -r requirements.txt - Memory Issues: Reduce batch size for large datasets
- Data Format: Ensure images are in supported formats (PNG, JPEG)
This project successfully demonstrates the power of ensemble learning and transfer learning in computer vision tasks. Starting from a failed baseline model stuck at 25% accuracy, we systematically diagnosed issues, implemented solutions, and achieved an impressive 97.14% accuracy using a weighted ensemble of three diverse models.
Project Status: โ
COMPLETED - Target accuracy achieved
Final Accuracy: 97.14% ๐
Ensemble Method: Weighted Averaging
Models Used: Custom CNN, ResNet50V2, Advanced CNN