Thanks to visit codestin.com
Credit goes to github.com

Skip to content

saad32170/battingclassifier

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

4 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Cricket Shot Classification ML Project

๐Ÿ† Achieved 97.14% Accuracy with Ensemble Learning

This project implements advanced machine learning models to classify cricket shots into four categories with exceptional accuracy using ensemble learning techniques.

๐ŸŽฏ Project Status: COMPLETED โœ…

Final Results:

  • Best Individual Model: ResNet50V2 (95.24% accuracy)
  • Best Ensemble Method: Weighted Averaging (97.14% accuracy)
  • Target Achieved: โœ… 95%+ accuracy goal exceeded

๐Ÿ“Š Quick Results Overview

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

Class-wise Performance (Best Ensemble):

  • Drive: 98% precision, 95% recall
  • Legglance-Flick: 96% precision, 96% recall
  • Pullshot: 97% precision, 99% recall
  • Sweep: 97% precision, 99% recall

๐Ÿ“ Project Structure

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)

๐Ÿš€ Quick Start

1. Install Dependencies

pip install -r requirements.txt

2. Use the Main Predictor (EASIEST!)

# 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/

3. Alternative Methods

# Original prediction script
python predict.py --image path/to/image.jpg

# Ensemble evaluation
python quick_ensemble.py

๐Ÿ—๏ธ Model Evolution

Journey from 25% to 97.14% Accuracy:

  1. Original Classifier (25% accuracy) โŒ

    • Failed due to double preprocessing and over-aggressive augmentation
  2. Working Classifier (88% accuracy) โœ…

    • Fixed preprocessing issues with single pipeline
  3. Advanced Classifier (91.64% accuracy) โœ…

    • Added Batch Normalization and deeper architecture
  4. Ensemble Classifier (97.14% accuracy) ๐Ÿ†

    • Combined 3 models using weighted averaging

๐ŸŽฏ Ensemble Methods Used

1. Hard Voting (Majority Vote)

  • Accuracy: 95.34%
  • Method: Each model votes, majority wins

2. Soft Voting (Probability Averaging)

  • Accuracy: 96.72%
  • Method: Average predicted probabilities

3. Weighted Averaging (Best Method)

  • Accuracy: 97.14% ๐Ÿ†
  • Method: Weighted average based on individual performance
  • Weights: [0.3, 0.4, 0.3] for [Custom CNN, ResNet50V2, Advanced CNN]

๐Ÿ”ง Technical Implementation

Model Architectures:

  • Custom CNN: Sequential CNN with 3 conv blocks
  • ResNet50V2: Transfer learning with ImageNet pre-training
  • Advanced CNN: Enhanced CNN with Batch Normalization

Training Configuration:

  • 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

Data Preprocessing:

  • Resize: All images to 224x224
  • Color Conversion: BGR to RGB
  • Normalization: Pixel values scaled to [0,1]

๐Ÿ“ˆ Performance Analysis

Individual Model Performance:

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 Performance:

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

๐ŸŽฎ Usage Examples

Basic Prediction:

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")

Batch Prediction:

# 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 Mode:

# Interactive prediction session
predictor.interactive_predictor()

๐Ÿ” Key Features

โœ… What Works:

  • 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

๐ŸŽฏ Problem Solutions:

  • 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

๐Ÿ“š Technical Concepts

Convolutional Neural Networks (CNNs)

  • Extract spatial features from cricket shot images
  • Translation invariant feature detection
  • Hierarchical feature learning

Transfer Learning

  • Use pre-trained models (ResNet50V2) on new tasks
  • Faster training and better performance
  • Leverage ImageNet features for cricket shots

Ensemble Learning

  • Combine multiple models for improved accuracy
  • Reduce variance and improve generalization
  • Weighted averaging based on individual performance

๐Ÿš€ Future Improvements

Data Quality:

  • Collect more diverse angles and lighting conditions
  • Add new shot types (cut, hook, defensive, etc.)
  • Include different players and batting styles

Model Enhancements:

  • Attention mechanisms for key body parts
  • Multi-scale feature extraction
  • Temporal information from video frames

Advanced Techniques:

  • Curriculum learning
  • Focal loss for hard examples
  • Advanced ensemble methods (stacking, boosting)

๐Ÿ† Achievements

Performance Milestones:

  1. โœ… Baseline Working: 88.00% accuracy
  2. โœ… Advanced Model: 91.64% accuracy
  3. โœ… Target Achieved: 97.14% accuracy
  4. โœ… Ensemble Success: Weighted averaging method

Technical Achievements:

  • Systematic problem diagnosis and solution
  • Architecture optimization with Batch Normalization
  • Successful transfer learning implementation
  • Effective ensemble learning techniques
  • Comprehensive error analysis

๐Ÿ“ž Support & Documentation

  • Complete Documentation: CRICKET_SHOT_CLASSIFICATION_PROJECT.md
  • Model Evolution: old_models/README.md
  • Error Analysis: misclassification_analyzer.py
  • Prediction Script: predict.py

Troubleshooting:

  1. Model Loading: Ensure .keras or .h5 files are in correct location
  2. Dependencies: Install all requirements with pip install -r requirements.txt
  3. Memory Issues: Reduce batch size for large datasets
  4. Data Format: Ensure images are in supported formats (PNG, JPEG)

๐ŸŽฏ Conclusion

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

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages