A multi-class image classification project comparing CNN models trained from scratch with transfer learning using MobileNetV2. This project demonstrates practical deep learning techniques including data augmentation, class weighting for imbalanced datasets, and fine-tuning pre-trained models.
This notebook implements and evaluates multiple approaches to garbage classification:
- Scratch CNNs: Custom convolutional networks trained from scratch on RGB and grayscale images
- Transfer Learning: MobileNetV2 pre-trained on ImageNet with optional fine-tuning
- Architecture Comparison: Tests different input sizes (128×128, 96×96) to balance accuracy and efficiency
The project uses a 10-class garbage classification dataset with the following categories:
- Battery
- Biological
- Cardboard
- Clothes
- Glass
- Metal
- Paper
- Plastic
- Shoes
- Trash
Data is split into 70% training, 10% validation, and 20% testing with class weights applied to address imbalance.
Best Model: Transfer Learning (MobileNetV2 with fine-tuning)
- Validation Accuracy: 89.06%
- Test F1-Score (Macro): 0.8789
- Parameters: ~3.5M
- Inference Time: Optimized for real-time deployment
Performance comparison shows that transfer learning significantly outperforms scratch models with fewer training epochs, making it ideal for resource-constrained environments.
- TensorFlow/Keras: Model building and training
- Scikit-learn: Model evaluation and confusion matrices
- Matplotlib/Pandas: Visualization and analysis
- NumPy: Numerical operations
- Configuration & Seeds: Sets up reproducible random states
- Data Loading: Creates train/validation/test splits with class weighting
- Exploratory Data Analysis: Visualizes class distribution and sample images
- Model Definitions: Reusable functions for architecture building and training
- Scratch Models: Trains CNNs from scratch on RGB and grayscale data
- Architecture Comparison: Tests different input sizes and model variants
- Transfer Learning: Implements MobileNetV2 with and without fine-tuning
- Results & Evaluation: Compares all models and performs final test evaluation
- Personal Photo Predictions: Demonstrates real-world inference on custom images
tensorflow
numpy
pandas
matplotlib
scikit-learn
- Clone this repository
- Install dependencies:
pip install -r requirements.txt - Ensure your dataset is structured as:
garbage/garbage/[class_folders]/[images] - Open
ML_Project.ipynbin Jupyter Notebook or JupyterLab - Run all cells sequentially
Note: Full dataset training may take 30-60 minutes depending on hardware. GPU acceleration is recommended.
| Model | Accuracy | Precision | Recall | F1-Score | Params |
|---|---|---|---|---|---|
| Scratch RGB 128×128 | 0.8423 | 0.8389 | 0.8423 | 0.8368 | 379K |
| Scratch Greyscale 128×128 | 0.7862 | 0.7821 | 0.7862 | 0.7805 | 189K |
| Transfer RGB (Fine-tuned) | 0.8906 | 0.8901 | 0.8906 | 0.8789 | 3.5M |
The model shows strong performance across most categories. Common confusion pairs:
- Metal ↔ Plastic: Similar reflective properties
- Cardboard ↔ Paper: Similar appearance and color
This project showcases:
- ✅ End-to-end machine learning pipeline design
- ✅ Multiple model architectures and training strategies
- ✅ Rigorous evaluation with appropriate metrics
- ✅ Handling of class imbalance through weighted training
- ✅ Transfer learning best practices
- ✅ Professional code organization and documentation
Nathan Carr (G00410214)
4th Year Machine Learning Module, Atlantic Technological University, Galway, 2026
This project is part of academic coursework at ATU Galway. Feel free to use for educational purposes.