File size: 3,883 Bytes
49036f6
 
 
 
 
 
 
 
 
 
84d0c9e
 
 
 
 
e932b8d
84d0c9e
 
 
 
 
 
 
 
 
 
e932b8d
 
49036f6
 
 
84d0c9e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
---
title: Trash Classification
colorFrom: green
colorTo: blue
sdk: streamlit
sdk_version: "1.44.1"
app_file: src/app.py
pinned: false
---


# Trash Classifier with Explainability

A deep learning project to classify recyclable waste items from images, enhanced with visual explainability tools. This pipeline includes model training, evaluation, and a real-time interactive app to demonstrate classification and model interpretation.

---

## Purpose and Why This Project Matters

Recycling is a crucial step toward sustainability, but it remains a manual and error-prone process. Automating trash classification helps:
- Improve waste sorting accuracy
- Reduce contamination in recycling streams
- Enable smart waste management systems

This project builds a lightweight yet powerful image classifier that recognizes 6 categories of recyclable and non-recyclable waste, enhanced with saliency-based interpretability to show *why* the model predicts what it does.

---




## Architecture Overview

- **Backbone Model**: MobileNetV2 (pretrained on ImageNet)
- **Classifier Head**: Fully connected layer with 6 output classes
- **Explainability**: Captum's Saliency, SmoothGrad, Guided Backpropagation
- **Deployment**: Streamlit app for real-time prediction and visualization


## Dataset Used

- **Name**: [TrashNet](https://github.com/garythung/trashnet)
- **Classes**: cardboard, glass, metal, paper, plastic, trash
- **Image Size**: 512x384 pixels
- **Class Distribution**:
  - Paper: 23.51%
  - Glass: 19.83%
  - Plastic: 19.07%
  - Metal: 16.22%
  - Cardboard: 15.95%
  - Trash: 5.42%
- **Handling**: Dataset split into `train`, `val`, `test` folders with stratification

---

## Techniques and Tools Used

- **Model Training**:
  - Transfer learning with frozen base layers
  - Adam optimizer, CrossEntropyLoss
  - TensorBoard for live metric tracking

- **Preprocessing**:
  - Resize & normalize images to 224x224
  - Stratified train-val-test split

- **Explainability**:
  - Captum's:
    - `Saliency`: Base gradients
    - `SmoothGrad`: Smoothed attribution
    - `GuidedBackprop`: Edge-focused explanations
  - Visualization: Matplotlib side-by-side comparisons

- **Deployment**:
  - Streamlit app with file uploader and toggle for saliency types

---

## Training Procedure

- Epochs: 10
- Optimizer: Adam (lr = 1e-4)
- Loss Function: CrossEntropy
- Early Stopping: Not needed (no overfitting)
- Logging: TensorBoard for accuracy/loss

Training monitored using:
- `Accuracy/train` and `Accuracy/val`
- `Loss/train` and `Loss/val`

**Training Accuracy/Validation Graph:**


<img src="eval_pics/acc_loss.png" width="60%"/>  

---

## Result Evaluation

| Metric          | Value    |
|----------------|----------|
| Train Accuracy  | 98.1%    |
| Val Accuracy    | 91.1%    |
| Train Loss      | 0.071    |
| Val Loss        | 0.312    |

**Evaluation Tools**:
- TensorBoard visualization
- Saliency-based interpretation (SmoothGrad + Guided)
- Streamlit demo UI

**Visual Placeholder:**

<table>
  <tr>
    <td><img src="eval_pics/streamlit_testpic.png" width="100%"/></td>
    <td><img src="eval_pics/saliency_map.png" width="100%"/></td>
  </tr>
</table>
---

## Overall Project Impact

- Demonstrates real-world machine learning application  
- High performance on imbalanced, noisy data  
- Includes interpretability and explainability tools  
- Easy-to-use UI for non-technical users  

This project shows a complete ML pipeline — from raw image data to deployed app with transparency in decision-making.

---

## Final Result

> A robust trash classifier trained on real data, achieving **91.1% accuracy** on validation and equipped with **visual explainability**, ready to be deployed in sustainability-focused applications, smart bins, or recycling plants.

**[Live Demo Link Coming Soon]**

**[Try Locally]**:  
```bash
streamlit run web_app/app.py
```

---