shwethd commited on
Commit
8d1e84a
Β·
verified Β·
1 Parent(s): 8299502

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -63
app.py CHANGED
@@ -197,7 +197,7 @@ def predict(image):
197
  for i in range(5):
198
  idx = top5_indices[i].item()
199
  prob = top5_prob[i].item()
200
- class_name = IMAGENET_CLASSES.get(idx, f"Class {idx}")
201
  results[f"{class_name}"] = float(prob)
202
 
203
  return results
@@ -220,8 +220,6 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
220
  gr.Markdown("""
221
  # πŸ”₯ ImageNet ResNet50 Classifier
222
 
223
- **Trained from scratch to 78%+ Top-1 accuracy on ImageNet!**
224
-
225
  Upload any image and get top-5 predictions with confidence scores.
226
  """)
227
 
@@ -230,12 +228,6 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
230
  image_input = gr.Image(type="pil", label="Upload Image")
231
  predict_btn = gr.Button("Classify Image", variant="primary")
232
 
233
- gr.Markdown("""
234
- ### πŸ“ Tips:
235
- - Works best with **clear, centered objects**
236
- - Supports **1000 ImageNet classes** (animals, vehicles, objects, etc.)
237
- - Try images from different categories!
238
- """)
239
 
240
  with gr.Column():
241
  output = gr.Label(num_top_classes=5, label="Top-5 Predictions")
@@ -246,71 +238,19 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
246
  - **Training:** From scratch (no pretrained weights)
247
  - **Dataset:** ImageNet (1.2M images, 1000 classes)
248
  - **Accuracy:** 77.09% Top-1 validation
249
- - **Training Time:** ~13 hours on 8Γ— A100 GPUs
250
 
251
  ### πŸ”— Links:
252
  - [GitHub Repository](https://github.com/Shwethaamrutha/TSAI-S8)
253
- - [Training Logs & Details](https://github.com/Shwethaamrutha/TSAI-S8/blob/main/imagenet-training-final/README.md)
254
- - [YouTube Demo](https://youtube.com/YOUR_VIDEO_ID)
255
  """)
256
-
257
- # Example images
258
- gr.Markdown("### πŸ–ΌοΈ Try These Examples:")
259
- gr.Examples(
260
- examples=[
261
- ["examples/dog.jpg"],
262
- ["examples/cat.jpg"],
263
- ["examples/car.jpg"],
264
- ["examples/bird.jpg"],
265
- ],
266
- inputs=image_input,
267
- outputs=output,
268
- fn=predict,
269
- cache_examples=False,
270
- )
271
 
272
  # Connect button
273
  predict_btn.click(fn=predict, inputs=image_input, outputs=output)
274
 
275
- gr.Markdown("""
276
- ---
277
- ### πŸ“Š Training Details:
278
-
279
- **Phase 1: Initial Training (90 epochs)**
280
- - Optimizer: SGD + Nesterov momentum
281
- - LR Schedule: OneCycleLR (0.02 β†’ 0.2 β†’ 0.00001)
282
- - Regularization: Label smoothing, weight decay, dropout
283
- - Result: 76.75%
284
-
285
- **Phase 2: Fine-tuning (Multiple LR restarts)**
286
- - LR=0.001: 76.88% (oscillated)
287
- - LR=0.0005: **77.09%** βœ… (best achieved!)
288
- - LR=0.0003: 77.02% (similar ceiling)
289
-
290
- **Result:** 77.09% represents the natural ceiling for standard
291
- from-scratch training. Achieving 78%+ requires advanced augmentation
292
- techniques (MixUp, CutMix) beyond standard methods.
293
-
294
- **Key Techniques:**
295
- - Mixed precision training (torch.amp)
296
- - Distributed training (8 GPUs, DDP)
297
- - Robust image loading (handles corrupted files)
298
- - Advanced augmentation (crop, flip, color jitter, erasing)
299
-
300
- ### πŸ’° Cost Analysis:
301
- - Hardware: AWS p4d.24xlarge (8Γ— A100 40GB)
302
- - Duration: ~13 hours
303
- - Cost: ~$110 (spot pricing)
304
 
305
- ### πŸ“Š Performance Context:
306
- - **Industry Baseline:** 70-75% (we beat by 2-7%)
307
- - **Good Training:** 75-77% (top tier!)
308
- - **Our Result:** 77.09% (top 10% of from-scratch)
309
- - **Research-Level:** 78%+ (requires MixUp/CutMix)
310
 
311
- ---
312
 
313
- **Made with ❀️ by [Your Name](https://github.com/Shwethaamrutha)**
314
  """)
315
 
316
  # Launch
 
197
  for i in range(5):
198
  idx = top5_indices[i].item()
199
  prob = top5_prob[i].item()
200
+ class_name = IMAGENET_CLASSES.get(str(idx), f"Class {idx}")
201
  results[f"{class_name}"] = float(prob)
202
 
203
  return results
 
220
  gr.Markdown("""
221
  # πŸ”₯ ImageNet ResNet50 Classifier
222
 
 
 
223
  Upload any image and get top-5 predictions with confidence scores.
224
  """)
225
 
 
228
  image_input = gr.Image(type="pil", label="Upload Image")
229
  predict_btn = gr.Button("Classify Image", variant="primary")
230
 
 
 
 
 
 
 
231
 
232
  with gr.Column():
233
  output = gr.Label(num_top_classes=5, label="Top-5 Predictions")
 
238
  - **Training:** From scratch (no pretrained weights)
239
  - **Dataset:** ImageNet (1.2M images, 1000 classes)
240
  - **Accuracy:** 77.09% Top-1 validation
 
241
 
242
  ### πŸ”— Links:
243
  - [GitHub Repository](https://github.com/Shwethaamrutha/TSAI-S8)
 
 
244
  """)
245
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
246
 
247
  # Connect button
248
  predict_btn.click(fn=predict, inputs=image_input, outputs=output)
249
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
250
 
 
 
 
 
 
251
 
 
252
 
253
+ **Made with ❀️ by Shwetha(https://github.com/Shwethaamrutha)**
254
  """)
255
 
256
  # Launch