π Live Application URL: https://ecosort-waste-classifier.onrender.com/
An automated, real-time waste classification system built with Python, TensorFlow, OpenCV, Flask, and HTML/CSS. The system classifies waste into Recyclable and Hazardous / Non-Recyclable categories using a custom deep Convolutional Neural Network (CNN) and provides a real-time computer vision detection stream.
- Automated Waste Classification CNN: Developed and trained a multi-block Convolutional Neural Network (CNN) in TensorFlow/Keras to categorize waste into recyclable and non-recyclable/hazardous types with high accuracy.
- Real-Time OpenCV Image Processing Pipeline: Built a low-latency image processing pipeline with OpenCV featuring Region-of-Interest (ROI) tracking, CLAHE contrast enhancement, color-coded dynamic bounding box overlays, and live FPS calculation.
- Full-Stack Flask Deployment: Deployed the trained model via a Flask web application with RESTful prediction APIs and live MJPEG streaming.
- Hyperparameter Tuning & Data Augmentation: Optimized model generalization and inference speed using spatial dropout, BatchNormalization, learning rate scheduling (
ReduceLROnPlateau), and data augmentations (rotation, zoom, shear, horizontal flips).
+-----------------------+
| Raw Waste Image |
| (Upload / Webcam) |
+-----------+-----------+
|
v
+-----------------------+
| OpenCV Pipeline |
| - ROI Extraction |
| - BGR -> RGB & CLAHE |
| - Resize (224x224) |
| - Normalization [0,1] |
+-----------+-----------+
|
v
+-----------------------------------------------------------------------------------------+
| Deep CNN Model |
| |
| [Input: 224x224x3] |
| | |
| +--> Block 1: Conv2D(32) -> BatchNorm -> Conv2D(32) -> MaxPool -> Dropout(0.25) |
| | |
| +--> Block 2: Conv2D(64) -> BatchNorm -> Conv2D(64) -> MaxPool -> Dropout(0.25) |
| | |
| +--> Block 3: Conv2D(128) -> BatchNorm -> Conv2D(128) -> MaxPool -> Dropout(0.30) |
| | |
| +--> Classifier: Flatten -> Dense(512, ReLU) -> BatchNorm -> Dropout(0.50) |
| |
| [Output: Dense(2, Softmax) -> Recyclable / Hazardous Probabilities] |
+-----------------------------------------------------------------------------------------+
|
v
+-------------------------------+
| Flask Web & API Server |
| - REST API (/api/classify) |
| - MJPEG Stream (/video_feed) |
| - Interactive Web Dashboard |
+---------------+---------------+
|
v
+-------------------------------+
| Client UI (HTML5/CSS3/JS) |
| - Real-time Confidence Meters |
| - Disposal Guidance |
| - Historical Analytics HUD |
+-------------------------------+
Smart-Waste-Classification/
βββ app.py # Flask web application & REST API server
βββ requirements.txt # Project dependencies
βββ .gitignore # Git ignore rules
βββ README.md # Project documentation
β
βββ data/ # Dataset
β βββ hazardous/ # Hazardous / Non-recyclable images
β βββ recyclable/ # Recyclable waste images
β
βββ models/ # Saved models and class labels
β βββ waste_classifier.h5 # Trained Keras CNN model weights
β βββ class_indices.json # Class index mapping metadata
β
βββ notebooks/ # Interactive Jupyter Notebooks
β βββ data_exploration.ipynb # Exploratory data analysis & sample visualizer
β βββ model_training.ipynb # Experimentation & hyperparameter tuning
β
βββ src/ # Core Machine Learning & CV Modules
β βββ data_preprocessing.py # OpenCV processing, normalization & augmentation
β βββ model.py # CNN architecture definitions
β βββ train.py # Model training pipeline & callbacks
β βββ evaluate.py # Evaluation metrics, confusion matrix & inference
β βββ realtime_detector.py # OpenCV real-time video stream processor
β βββ utils.py # Helper functions & disposal metadata
β
βββ static/ # Web Assets
β βββ css/
β β βββ style.css # Modern glassmorphism CSS design system
β βββ js/
β β βββ main.js # Drag & drop upload and AJAX classification
β β βββ webcam.js # Browser camera stream and capture handling
β βββ img/ # Training curves and confusion matrix plots
β
βββ templates/ # Flask Jinja2 HTML Templates
βββ base.html # Master layout & responsive navigation
βββ index.html # Main dashboard
βββ realtime.html # OpenCV real-time video stream view
βββ history.html # Classification activity logs & stats
βββ about.html # Architecture breakdown & specs
- Python 3.9+ / 3.10 / 3.11
- pip package manager
# Clone the repository
git clone https://github.com/dhileepant/Smart-Waste-Classification.git
cd Smart-Waste-Classification
# Create virtual environment
python -m venv venv
# Activate virtual environment
# On Windows:
venv\Scripts\activate
# On Linux/macOS:
source venv/bin/activate
# Install dependencies
pip install -r requirements.txtTo train the CNN model on the dataset and save the trained weights:
python src/train.pyTrained weights will be saved to models/waste_classifier.h5 and training curves to static/img/training_history.png.
To compute per-class precision, recall, F1-score, and generate the confusion matrix:
python src/evaluate.pyTo start the web server and access the interactive dashboard:
python app.pyOpen your browser and navigate to: http://127.0.0.1:5000
- Endpoint:
POST /api/classify - Body:
form-datawith keyfile(image file) - Sample Response:
{
"success": true,
"result": {
"category": "recyclable",
"title": "Recyclable Waste",
"confidence": 98.42,
"color": "#10b981",
"bin_type": "Blue / Green Recycling Bin",
"disposal_instructions": "Rinse containers to remove food residue. Flatten cardboard boxes and crush plastic bottles to save space before placing in the blue recycling bin.",
"environmental_impact": "Recycling 1 ton of plastic saves up to 2,000 gallons of gasoline and reduces carbon emissions significantly.",
"inference_time_ms": 11.45,
"timestamp": "2025-11-20 16:32:10"
}
}- Endpoint:
POST /api/classify - Headers:
Content-Type: application/json - Body:
{
"image": "data:image/jpeg;base64,/9j/4AAQSkZJRg..."
}- Endpoint:
GET /api/stats - Sample Response:
{
"total_classified": 28,
"recyclable_count": 22,
"hazardous_count": 6,
"average_latency_ms": 12.3
}| Component | Specification |
|---|---|
| Input Tensor Shape |
|
| Convolutional Layers | 6 Conv2D layers ( |
| Normalization & Regularization | Batch Normalization on all blocks, Spatial Dropout ( |
| Optimizer | Adam (Initial Learning Rate: |
| Learning Rate Schedule |
ReduceLROnPlateau (factor: 0.3, patience: 3 epochs) |
| Loss Function | Categorical Cross-Entropy |
| Augmentation |
|
| Inference Latency |
|
| Category | Typical Items | Recommended Bin | Environmental Impact |
|---|---|---|---|
| Recyclable | Plastic bottles, cardboard, paper, aluminum cans, glass | Blue / Green Recycling Bin | Conserves raw timber, petroleum, and reduces landfill mass. |
| Hazardous | Batteries, electronic boards (e-waste), chemical solvents, medical items | Red / Designated E-Waste Center | Prevents toxic heavy metals (lead, mercury, cadmium) from contaminating groundwater. |
This project is open-source under the MIT License.