File size: 5,917 Bytes
9bd8ee0 dccd033 cdfe335 ab2d9d5 9bd8ee0 06da7a4 9bd8ee0 a624552 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 | ---
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. |