Ashutosh4902's picture
Upload 6 files
fa550e1 verified
|
Raw
History Blame Contribute Delete
4.76 kB
---
title: E-commerce Product Classifier
emoji: πŸ›οΈ
colorFrom: blue
colorTo: green
sdk: docker
app_file: app.py
pinned: false
---
# E-commerce Product Classifier with Grad-CAM
**Live Product Image Classification using Deep Learning**
Production-ready Flask web application for e-commerce product classification using trained Custom CNN, MobileNetV2, and ResNet50 models with real-time Grad-CAM explainability visualization.
## ✨ Features
- **3 Trained Models**: Custom CNN, MobileNetV2, ResNet50 (all optimized)
- **Grad-CAM Visualization**: See exactly which image regions influenced predictions
- **Real-time Predictions**: Upload any image and get instant results
- **9 Product Categories**: BABY_PRODUCTS, BEAUTY_HEALTH, CLOTHING_ACCESSORIES_JEWELLERY, ELECTRONICS, GROCERY, HOBBY_ARTS_STATIONERY, HOME_KITCHEN_TOOLS, PET_SUPPLIES, SPORTS_OUTDOOR
- **Model Comparison**: Side-by-side metrics of all 3 models
- **Production-Grade**: Thread-safe, auto-cleanup, error handling, logging
- **Responsive UI**: Works perfectly on desktop, tablet, mobile
- **Accessible**: WCAG 2.1 compliant (keyboard navigation, screen readers)
## πŸš€ How to Use
1. **Upload an Image**: Drag-and-drop or click to select a product image
2. **Select Models**: Choose which models to run (or run all 3)
3. **Get Predictions**: See confidence scores and Grad-CAM heatmaps
4. **Analyze Results**: View model comparisons and explanations
## πŸ“Š Model Performance
| Model | Accuracy | Precision | Recall | F1-Score | Size |
|-------|----------|-----------|--------|----------|------|
| Custom CNN | 45.47% | 41.17% | 45.47% | 0.3858 | 8.9 MB |
| MobileNetV2 | 71.76% | 71.13% | 71.76% | 0.7106 | 33 MB |
| ResNet50 | 76.93% | 77.39% | 76.93% | 0.7680 | 333 MB |
## πŸ”§ Technical Details
- **Framework**: Flask (Python backend)
- **Models**: TensorFlow/Keras (.keras format)
- **Input Size**: 224Γ—224 pixels
- **Classes**: 9 product categories
- **Explainability**: Grad-CAM overlay visualization
- **Deployment**: Docker on Hugging Face Spaces
## πŸ“ Structure
```
.
β”œβ”€β”€ app.py # Flask backend (production-optimized)
β”œβ”€β”€ requirements.txt # Python dependencies
β”œβ”€β”€ Dockerfile # Container configuration
β”œβ”€β”€ README.md # This file
β”œβ”€β”€ templates/
β”‚ └── index.html # HTML template
β”œβ”€β”€ static/
β”‚ β”œβ”€β”€ css/styles.css # Styling (responsive design)
β”‚ └── js/app.js # Frontend (retry logic, state mgmt)
└── nn_ecommerce_outputs/
β”œβ”€β”€ models/
β”‚ β”œβ”€β”€ custom_cnn.keras
β”‚ β”œβ”€β”€ mobilenetv2.keras
β”‚ └── resnet50.keras
β”œβ”€β”€ metadata/
β”‚ β”œβ”€β”€ class_names.json
β”‚ └── model_manifest.json
└── tables/
└── (CSV files with metrics)
```
## πŸ›  Production Features
βœ… **Thread-safe model caching** - Safe for concurrent requests
βœ… **Automatic cleanup** - Old generated files cleaned up
βœ… **Retry logic** - Network failures handled gracefully
βœ… **Input validation** - File type & size checks
βœ… **Structured logging** - Debug everything
βœ… **Error handling** - User-friendly messages
βœ… **Progress tracking** - Real-time prediction progress
βœ… **Accessible UI** - WCAG 2.1 compliant
## πŸ“± Browser Support
- Chrome/Chromium (latest)
- Firefox (latest)
- Safari (latest)
- Edge (latest)
- Mobile browsers (iOS Safari, Chrome Mobile)
## 🚨 Troubleshooting
**Q: Models not loading?**
A: Check that `.keras` files exist in `nn_ecommerce_outputs/models/`
**Q: Predictions are slow?**
A: First prediction loads models (normal), subsequent are faster
**Q: Image upload fails?**
A: Check file size < 12 MB and format (JPG, PNG, WEBP, BMP)
**Q: Want to see logs?**
A: Check Space Settings β†’ Logs tab for detailed information
## πŸ“š Resources
- [Flask Documentation](https://flask.palletsprojects.com)
- [TensorFlow/Keras](https://tensorflow.org)
- [Grad-CAM Paper](https://arxiv.org/abs/1610.02055)
- [HF Spaces Docs](https://huggingface.co/docs/hub/spaces)
## πŸ“„ License
MIT License - Free for academic and commercial use
## 🀝 About This Project
This is a comprehensive deep learning project for e-commerce product classification featuring:
- Custom CNN trained from scratch
- Transfer learning with MobileNetV2 and ResNet50
- Extensive explainability analysis with Grad-CAM
- Production-ready web deployment
**Author**: Ashutosh Rajendra Patil
**Institution**: University of Europe for Applied Sciences
**Dataset**: Kaggle ecommerce_product_images_18K (18,175 images, 9 categories)
---
**Status**: βœ… Production Ready | **Python**: 3.9+ | **TensorFlow**: 2.15.0 | **Updated**: June 2026