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
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
- Clone this repository
- Install dependencies:
pip install tensorflow opencv-python numpy pillow matplotlib seaborn scikit-learn
- Download the trained models:
- Run real-time detection:
python realtime_trash_detection_TRANSFER_LEARNING.py # For transfer learning models
python realtime_trash_detection_CNN.py # For CNN model
- Training Accuracy: 79.35%
- Validation Accuracy: 72.11%
- Average inference time: ~40ms per frame
- Architecture: 4 convolutional blocks with Conv2D layers (32→64 filters)
- Training Accuracy: 99.92%
- Validation Accuracy: 75.75%
- More balanced predictions across categories
- Training Accuracy: 99.63%
- Validation Accuracy: 34.79%
- Note: Shows significant misclassification of most categories as 'paper'
DEMO.Realtime_trash_detection_CNN.mp4
├── 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
- Webcam for real-time detection
- Minimum 8GB RAM
- GPU recommended for faster training (or use Colab T4 GPU)
- Python 3.7+
- TensorFlow 2.x
- OpenCV
- NumPy
- Matplotlib
- PIL (Python Imaging Library)
- Seaborn
- Scikit-learn
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.
- Gowtham M, IIIrd Year (VCET)