AIOmarRehan commited on
Commit
a624552
·
verified ·
1 Parent(s): 9bd8ee0

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +189 -1
README.md CHANGED
@@ -11,4 +11,192 @@ license: mit
11
  short_description: InceptionV3 sports ball classifier with Gradio.
12
  ---
13
 
14
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
  short_description: InceptionV3 sports ball classifier with Gradio.
12
  ---
13
 
14
+ # Sports Ball Classification using InceptionV3
15
+
16
+ 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.
17
+
18
+ ## Overview
19
+
20
+ 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.
21
+
22
+ ## Key Features
23
+
24
+ - Transfer learning with InceptionV3 pre-trained on ImageNet
25
+ - Comprehensive data preprocessing and quality analysis
26
+ - Automated data balancing through augmentation
27
+ - Two-stage training: feature extraction followed by fine-tuning
28
+ - FastAPI deployment for easy inference
29
+ - Docker support for containerized deployment
30
+ - Rigorous evaluation with multiple metrics (precision, recall, F1-score, ROC curves)
31
+
32
+ ## Project Structure
33
+
34
+ ```
35
+ InceptionV3_Sports_Balls_Classification/
36
+ ├── app/
37
+ │ ├── main.py # FastAPI application
38
+ │ └── model.py # Model loading and prediction logic
39
+ ├── Notebook and Py File/
40
+ │ ├── Sports_Balls_Classification.ipynb
41
+ ├── saved_model/
42
+ │ └── Sports_Balls_Classification.h5
43
+ ├── Results/
44
+ │ └── InceptionV3_Sports_Balls_Classification.mp4
45
+ ├── requirements.txt
46
+ ├── Dockerfile
47
+ └── README.md
48
+ ```
49
+
50
+ ## Installation
51
+
52
+ ### Local Setup
53
+
54
+ 1. Clone the repository:
55
+ ```bash
56
+ git clone https://github.com/yourusername/sports-ball-classifier.git
57
+ cd sports-ball-classifier
58
+ ```
59
+
60
+ 2. Install dependencies:
61
+ ```bash
62
+ pip install -r requirements.txt
63
+ ```
64
+
65
+ ### Docker Setup
66
+
67
+ Build and run using Docker:
68
+ ```bash
69
+ docker build -t sports-ball-classifier .
70
+ docker run -p 8000:8000 sports-ball-classifier
71
+ ```
72
+
73
+ ## Usage
74
+
75
+ ### Running the API
76
+
77
+ Start the FastAPI server:
78
+ ```bash
79
+ uvicorn app.main:app --host 0.0.0.0 --port 8000
80
+ ```
81
+
82
+ The API will be available at `http://localhost:8000`
83
+
84
+ ### Making Predictions
85
+
86
+ Send a POST request to the `/predict` endpoint:
87
+
88
+ ```python
89
+ import requests
90
+
91
+ url = "http://localhost:8000/predict"
92
+ files = {"file": open("path/to/sports_ball_image.jpg", "rb")}
93
+ response = requests.post(url, files=files)
94
+ print(response.json())
95
+ ```
96
+
97
+ Response format:
98
+ ```json
99
+ {
100
+ "predicted_label": "basketball",
101
+ "confidence": 0.985,
102
+ "probabilities": {
103
+ "basketball": 0.985,
104
+ "soccer_ball": 0.012,
105
+ "tennis_ball": 0.003
106
+ }
107
+ }
108
+ ```
109
+
110
+ ### Using the Notebook
111
+
112
+ Open and run the Jupyter notebook for training and evaluation:
113
+ ```bash
114
+ jupyter notebook "Notebook / Sports_Balls_Classification.ipynb"
115
+ ```
116
+
117
+ ## Model Architecture
118
+
119
+ The model uses InceptionV3 as a feature extractor with custom classification layers:
120
+
121
+ - Base: InceptionV3 (pre-trained on ImageNet, frozen initially)
122
+ - Global Average Pooling 2D
123
+ - Dense layer (512 units, ReLU activation)
124
+ - Dropout (0.5)
125
+ - Output layer (softmax activation)
126
+ ```python
127
+ x = GlobalAveragePooling2D()(inception.output)
128
+ x = Dense(512, activation='relu')(x)
129
+ x = Dropout(0.5)(x)
130
+ prediction = Dense(len(le.classes_), activation='softmax')(x)
131
+ model = Model(inputs=inception.input, outputs=prediction)
132
+ model.summary()
133
+ ```
134
+
135
+ ### Training Strategy
136
+
137
+ **Stage 1: Feature Extraction (5 epochs)**
138
+ - Freeze InceptionV3 base layers
139
+ - Train only top classification layers
140
+ - Learn task-specific patterns
141
+
142
+ **Stage 2: Fine-Tuning (10 epochs)**
143
+ - Unfreeze last 30 layers of InceptionV3
144
+ - Train entire model with lower learning rate
145
+ - Adapt deep features to sports ball classification
146
+
147
+ ## Data Preprocessing
148
+
149
+ The preprocessing pipeline includes:
150
+
151
+ 1. Corruption and quality checks
152
+ 2. Brightness and contrast analysis
153
+ 3. Class balancing through augmentation
154
+ 4. Normalization and resizing
155
+ 5. TensorFlow data pipeline optimization (prefetching, caching, parallel processing)
156
+
157
+ ## Evaluation Metrics
158
+
159
+ The model is evaluated using:
160
+
161
+ - Accuracy
162
+ - Precision, Recall, F1-Score (per class and macro-averaged)
163
+ - Confusion Matrix
164
+ - ROC Curves (one-vs-rest)
165
+ - Classification Report
166
+
167
+ ![Confusion Matrix](https://files.catbox.moe/ror363.png)
168
+ ![ROC Curves](https://files.catbox.moe/0w580o.png)
169
+
170
+ ## Requirements
171
+
172
+ ![Python](https://img.shields.io/badge/Python-3.8+-3776AB?logo=python&logoColor=white)
173
+ ![TensorFlow](https://img.shields.io/badge/TensorFlow-2.x-FF6F00?logo=tensorflow&logoColor=white)
174
+ ![FastAPI](https://img.shields.io/badge/FastAPI-009688?logo=fastapi&logoColor=white)
175
+ ![Uvicorn](https://img.shields.io/badge/Uvicorn-ASGI-499848)
176
+ ![Pillow](https://img.shields.io/badge/Pillow-Image%20Processing-8CAAE6)
177
+ ![NumPy](https://img.shields.io/badge/NumPy-013243?logo=numpy&logoColor=white)
178
+ ![scikit--learn](https://img.shields.io/badge/scikit--learn-F7931E?logo=scikitlearn&logoColor=white)
179
+ ![Matplotlib](https://img.shields.io/badge/Matplotlib-11557C)
180
+ ![Seaborn](https://img.shields.io/badge/Seaborn-Statistical%20Viz-4C72B0)
181
+ ![pandas](https://img.shields.io/badge/pandas-150458?logo=pandas&logoColor=white)
182
+
183
+ See `requirements.txt` for complete dependencies.
184
+
185
+ ## Performance
186
+
187
+ The model achieves strong performance across all classes after addressing:
188
+ - Class imbalance through augmentation
189
+ - Image quality issues (dark, bright, low contrast images)
190
+ - Proper train/validation/test splits (80/10/10)
191
+
192
+ Detailed metrics available in the notebook evaluation section.
193
+
194
+ ## Check the Results
195
+
196
+ <a href="https://files.catbox.moe/gn2xut.mp4">
197
+ <img src="https://files.catbox.moe/851c5y.avif" width="300">
198
+ </a>
199
+
200
+ ## License
201
+
202
+ This project is licensed under the MIT License.