Skip to content

metehanulusoy/garbage-classifier

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

♻️ Garbage Classifier

A real-time garbage classification web app powered by MobileNetV2 Transfer Learning.
Point your camera at trash — it tells you what type it is. 📷♻️

🚀 Live Demo → metehanulusoy.github.io/garbage-classifier


📸 Demo

The app has two modes — switch between them with the buttons at the top:

  • 📷 Camera Mode — Real-time scanner with an animated targeting overlay. Classifies what's in the box every ~900ms.
  • 📁 Upload Mode — Drag & drop or click to upload a photo for instant classification.

🗂️ Categories

The model identifies 6 types of garbage:

Category Examples
📦 Cardboard Boxes, packaging, cartons
🍾 Glass Bottles, jars, containers
🔩 Metal Cans, foil, utensils
📄 Paper Newspapers, bags, cups
🧴 Plastic Bottles, bags, containers
🗑️ Trash General waste, non-recyclables

🧠 How It Works

This project uses Transfer Learning — instead of training from scratch, a powerful pretrained CNN is reused with a small custom classification layer on top.

Input Image (224×224)
       ↓
MobileNetV2 (pretrained on ImageNet, frozen)
       ↓
Global Average Pooling → [1280] feature vector
       ↓
Dense Layer (1280 → 6)  ←  trained on garbage dataset
       ↓
Softmax → class probabilities

Browser inference (no backend required):

  • MobileNetV2 base is loaded from @tensorflow-models/mobilenet CDN
  • Only the custom Dense layer weights (~30 KB) are stored in this repo
  • mobilenet.infer(image, true) extracts the 1280-dim embedding
  • Dense weights are applied manually via tf.matMul + tf.softmax

This keeps the app fast — no 80 MB model download — and fully client-side.


🏋️ Training

Dataset: Garbage Classification — 2,500+ images across 6 classes Base model: MobileNetV2 (include_top=False, ImageNet weights, frozen) Custom head: GlobalAveragePooling2D → Dense(6, softmax) Optimizer: Adam | Epochs: 10 | Validation Accuracy: ~87.3%

To retrain:

pip install -r requirements.txt
python train.py
# Saves garbage_model.h5

🌐 Running Locally

No installation needed — it's a single HTML file.

git clone https://github.com/metehanulusoy/garbage-classifier.git
cd garbage-classifier

# Serve locally (camera requires localhost or HTTPS)
python -m http.server 8000
# Visit http://localhost:8000

📁 Project Structure

garbage-classifier/
├── index.html              # Web app — camera + upload modes
├── train.py                # Model training script
├── requirements.txt        # Python dependencies
├── model/
│   ├── dense_weights.bin   # Trained Dense layer weights (~30 KB)
│   └── config.json         # Class names & weight shapes
└── README.md

🛠️ Tech Stack

Layer Technology
Model training Python, TensorFlow / Keras
Browser inference TensorFlow.js
Pretrained base @tensorflow-models/mobilenet
Camera API HTML5 getUserMedia
Overlay rendering HTML5 Canvas
Hosting GitHub Pages

👤 Author

Metehan Ulusoy — Computer Engineering Student

GitHub


📄 License

MIT License — see LICENSE for details.

About

Garbage classification web app using MobileNet transfer learning — detects cardboard, glass, metal, paper, plastic, and trash from photos

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors