Skip to content

Real-time trash classification using CNN and transfer learning (MobileNetV2 and NASNetMobile) to identify waste materials

Notifications You must be signed in to change notification settings

g-wtham/trash-classification-cnn-transferlearning

Repository files navigation

Real-time Garbage Classification using CNN and Transfer Learning

This project implements real-time garbage classification using both Custom CNN and Transfer Learning approaches (MobileNetV2 & NASNetMobile). The system can identify different types of waste materials through computer vision to help automate waste sorting processes and improve recycling efficiency. Includes the complete guide to re-implement this on your own!

To view the web version & the code : Garbage Classification using FastAPI

Dataset Details

The project uses the TrashNet dataset:

  • Contains 2527 images across 6 categories
  • Image Resolution: 300x300 pixels
  • Format: JPG
  • Categories: cardboard, glass, metal, paper, plastic, trash
  • Source: TrashNet on Kaggle

Installation & Setup

  1. Clone this repository
  2. Install dependencies:
pip install tensorflow opencv-python numpy pillow matplotlib seaborn scikit-learn
  1. Download the trained models:
  1. Run real-time detection:
python realtime_trash_detection_TRANSFER_LEARNING.py  # For transfer learning models
python realtime_trash_detection_CNN.py               # For CNN model

Models & Results

1. Custom CNN Architecture

  • Training Accuracy: 79.35%
  • Validation Accuracy: 72.11%
  • Average inference time: ~40ms per frame
  • Architecture: 4 convolutional blocks with Conv2D layers (32→64 filters)

2. Transfer Learning Results

NASNet Mobile (30 epochs)

  • Training Accuracy: 99.92%
  • Validation Accuracy: 75.75%
  • More balanced predictions across categories

MobileNetV2 (20 epochs)

  • Training Accuracy: 99.63%
  • Validation Accuracy: 34.79%
  • Note: Shows significant misclassification of most categories as 'paper'

Results Visualization

CNN Results

Training after 50 Epochs

Training after 50 Epochs Train Validation Accuracy

MobileNetV2 Results

MobileNetV2 Training & Validation Accuracy

MobileNetV2 Confusion Matrix

NASNetMobile Results

NASNetMobile Training & Validation Accuracy

NASNetMobile Confusion Matrix

DEMO.Realtime_trash_detection_CNN.mp4

Project Structure


├── models/
│   ├── CNN_trained_model.keras
│   ├── trash_classification_tf_mobilenet.h5
│   └── trash_classification_tf_nasnet.h5
├── /
│   ├── CNN Training.ipynb
│   ├── MobileNetV2 Transfer Learning.ipynb
│   └── NasNetMobile Transfer Learning.ipynb
└── /
    ├── realtime_trash_detection_CNN.py
    └── realtime_trash_detection_TRANSFER_LEARNING.py

Requirements

Hardware Requirements:

  • Webcam for real-time detection
  • Minimum 8GB RAM
  • GPU recommended for faster training (or use Colab T4 GPU)

Software Requirements:

  • Python 3.7+
  • TensorFlow 2.x
  • OpenCV
  • NumPy
  • Matplotlib
  • PIL (Python Imaging Library)
  • Seaborn
  • Scikit-learn

Conclusion

Based on the results, NASNetMobile performs better than both the custom CNN and MobileNetV2 for this specific waste classification task, achieving higher validation accuracy and more balanced predictions across categories.

Done by

  • Gowtham M, IIIrd Year (VCET)

About

Real-time trash classification using CNN and transfer learning (MobileNetV2 and NASNetMobile) to identify waste materials

Topics

Resources

Stars

Watchers

Forks