| --- |
| title: Sports Ball Classification Inceptionv3 |
| emoji: ⚽ |
| colorFrom: purple |
| colorTo: blue |
| sdk: gradio |
| sdk_version: 6.6.0 |
| app_file: app.py |
| pinned: false |
| license: mit |
| short_description: InceptionV3 sports ball classifier with Gradio. |
| models: |
| - AIOmarRehan/Sports_Balls_Classification_InceptionV3 |
| datasets: |
| - AIOmarRehan/Sports-Balls |
| --- |
| |
| # Sports Ball Classification using InceptionV3 |
|
|
| A deep learning image classification model that identifies different types of sports balls using transfer learning with InceptionV3. The model achieves high accuracy through careful data preprocessing, augmentation, and a two-stage training strategy. |
|
|
| ## Overview |
|
|
| This project demonstrates a production-ready approach to image classification, focusing on data quality, preprocessing pipelines, and comprehensive evaluation. The model can classify various sports balls including basketballs, soccer balls, tennis balls, baseballs, and more. |
|
|
| ## Key Features |
|
|
| - Transfer learning with InceptionV3 pre-trained on ImageNet |
| - Comprehensive data preprocessing and quality analysis |
| - Automated data balancing through augmentation |
| - Two-stage training: feature extraction followed by fine-tuning |
| - FastAPI deployment for easy inference |
| - Docker support for containerized deployment |
| - Rigorous evaluation with multiple metrics (precision, recall, F1-score, ROC curves) |
|
|
| ## Project Structure |
|
|
| ``` |
| InceptionV3_Sports_Balls_Classification/ |
| ├── app/ |
| │ ├── main.py # FastAPI application |
| │ └── model.py # Model loading and prediction logic |
| ├── Notebook and Py File/ |
| │ ├── Sports_Balls_Classification.ipynb |
| ├── saved_model/ |
| │ └── Sports_Balls_Classification.h5 |
| ├── Results/ |
| │ └── InceptionV3_Sports_Balls_Classification.mp4 |
| ├── requirements.txt |
| ├── Dockerfile |
| └── README.md |
| ``` |
|
|
| ## Installation |
|
|
| ### Local Setup |
|
|
| 1. Clone the repository: |
| ```bash |
| git clone https://github.com/yourusername/sports-ball-classifier.git |
| cd sports-ball-classifier |
| ``` |
|
|
| 2. Install dependencies: |
| ```bash |
| pip install -r requirements.txt |
| ``` |
|
|
| ### Docker Setup |
|
|
| Build and run using Docker: |
| ```bash |
| docker build -t sports-ball-classifier . |
| docker run -p 8000:8000 sports-ball-classifier |
| ``` |
|
|
| ## Usage |
|
|
| ### Running the API |
|
|
| Start the FastAPI server: |
| ```bash |
| uvicorn app.main:app --host 0.0.0.0 --port 8000 |
| ``` |
|
|
| The API will be available at `http://localhost:8000` |
|
|
| ### Making Predictions |
|
|
| Send a POST request to the `/predict` endpoint: |
|
|
| ```python |
| import requests |
| |
| url = "http://localhost:8000/predict" |
| files = {"file": open("path/to/sports_ball_image.jpg", "rb")} |
| response = requests.post(url, files=files) |
| print(response.json()) |
| ``` |
|
|
| Response format: |
| ```json |
| { |
| "predicted_label": "basketball", |
| "confidence": 0.985, |
| "probabilities": { |
| "basketball": 0.985, |
| "soccer_ball": 0.012, |
| "tennis_ball": 0.003 |
| } |
| } |
| ``` |
|
|
| ### Using the Notebook |
|
|
| Open and run the Jupyter notebook for training and evaluation: |
| ```bash |
| jupyter notebook "Notebook / Sports_Balls_Classification.ipynb" |
| ``` |
|
|
| ## Model Architecture |
|
|
| The model uses InceptionV3 as a feature extractor with custom classification layers: |
|
|
| - Base: InceptionV3 (pre-trained on ImageNet, frozen initially) |
| - Global Average Pooling 2D |
| - Dense layer (512 units, ReLU activation) |
| - Dropout (0.5) |
| - Output layer (softmax activation) |
| ```python |
| x = GlobalAveragePooling2D()(inception.output) |
| x = Dense(512, activation='relu')(x) |
| x = Dropout(0.5)(x) |
| prediction = Dense(len(le.classes_), activation='softmax')(x) |
| model = Model(inputs=inception.input, outputs=prediction) |
| model.summary() |
| ``` |
|
|
| ### Training Strategy |
|
|
| **Stage 1: Feature Extraction (5 epochs)** |
| - Freeze InceptionV3 base layers |
| - Train only top classification layers |
| - Learn task-specific patterns |
|
|
| **Stage 2: Fine-Tuning (10 epochs)** |
| - Unfreeze last 30 layers of InceptionV3 |
| - Train entire model with lower learning rate |
| - Adapt deep features to sports ball classification |
|
|
| ## Data Preprocessing |
|
|
| The preprocessing pipeline includes: |
|
|
| 1. Corruption and quality checks |
| 2. Brightness and contrast analysis |
| 3. Class balancing through augmentation |
| 4. Normalization and resizing |
| 5. TensorFlow data pipeline optimization (prefetching, caching, parallel processing) |
|
|
| ## Evaluation Metrics |
|
|
| The model is evaluated using: |
|
|
| - Accuracy |
| - Precision, Recall, F1-Score (per class and macro-averaged) |
| - Confusion Matrix |
| - ROC Curves (one-vs-rest) |
| - Classification Report |
|
|
|  |
|  |
|
|
| ## Requirements |
|
|
|  |
|  |
|  |
|  |
|  |
|  |
|  |
|  |
|  |
|  |
|
|
| See `requirements.txt` for complete dependencies. |
|
|
| ## Performance |
|
|
| The model achieves strong performance across all classes after addressing: |
| - Class imbalance through augmentation |
| - Image quality issues (dark, bright, low contrast images) |
| - Proper train/validation/test splits (80/10/10) |
|
|
| Detailed metrics available in the notebook evaluation section. |
|
|
| ## Check the Results |
|
|
| <a href="https://files.catbox.moe/gn2xut.mp4"> |
| <img src="https://files.catbox.moe/851c5y.avif" width="300"> |
| </a> |
|
|
| ## License |
|
|
| This project is licensed under the MIT License. |