A deep learning project for classifying waste images using a Convolutional Neural Network (CNN) in PyTorch. This project uses the RealWaste dataset from the UCI Machine Learning Repository and demonstrates data preprocessing, augmentation, model training, evaluation, and visualization.

Figure: Sample image with its label for all 9 classes.
RealWaste CNN/
├── main.ipynb # Jupyter notebook with all code
├── README.md # Project documentation
├── checkpoint.pth # Model checkpoint
├── history.json # Training history
├── dataset/ # Original dataset
├── dataset_split/ # Train/val/test splits
- Source: UCI RealWaste Dataset
- Classes: Cardboard, Food Organics, Glass, Metal, Miscellaneous Trash, Paper, Plastic, Textile Trash, Vegetation
- Preprocessing: Images are split into train/val/test folders and augmented to balance class counts.
- Clone the repository:
git clone https://github.com/InduwaraGunasena/RealWaste-Image-Classification.git cd RealWaste-Image-Classification - Install dependencies:
- Python 3.8+
- PyTorch
- torchvision
- scikit-learn
- matplotlib
- tqdm
- pandas
- seaborn
- Jupyter Notebook
pip install torch torchvision scikit-learn matplotlib tqdm pandas seaborn jupyter
- Download the RealWaste dataset and place it in the
dataset/realwaste-main/RealWastedirectory.
Open main.ipynb in Jupyter Notebook and run the cells sequentially:
- Environment Setup:
- Detects GPU and sets device.
- Data Preparation:
- Splits dataset into train/val/test.
- Augments training data for class balance.
- Optionally caches datasets for faster loading.
- Data Visualization:
- Shows sample images and class distributions.
- Model Definition:
- Defines a custom CNN architecture with batch normalization, dropout, and global average pooling.
- Training:
- Trains the model with progress bars showing loss and accuracy.
- Supports early stopping and checkpointing.
- Evaluation:
- Plots training history (loss, accuracy, precision, recall).
- Evaluates on test set and prints metrics.
- Displays confusion matrix and classification report.
- Prediction Visualization:
- Shows grid of test images with predicted/true labels and probability distributions.
- Training History: Plots for loss, accuracy, precision, and recall over epochs.
- Test Predictions: Visual grids showing model predictions and confidence for test images.
- Confusion Matrix: Visualizes class-wise performance.
- Classification Report: Detailed metrics for each class.
Our custom CNN model is designed for robust image classification with the following layer-wise structure:
- Input Layer: Accepts RGB images of size 128x128.
- Block 1: Two convolutional layers (64 filters), each followed by batch normalization and ReLU activation, then max pooling and dropout.
- Block 2: Two convolutional layers (128 filters), batch normalization, ReLU, max pooling, and dropout.
- Block 3: Two convolutional layers (256 filters), batch normalization, ReLU, max pooling, and dropout.
- Block 4: One convolutional layer (256 filters), batch normalization, ReLU, and dropout.
- Global Average Pooling: Reduces spatial dimensions to a single value per channel.
- Fully Connected Layers:
- Dense layer (128 units) with ReLU and dropout
- Output layer (for 9 classes)
This architecture uses batch normalization and dropout throughout to improve generalization and training stability.
Model Summary:
The model contains multiple convolutional blocks, global average pooling, and fully connected layers, resulting in a compact and efficient design for multi-class waste classification.

Figure: Layer-wise summary of the CNN architecture.
After 50 epochs of training, the model achieved:
- Accuracy: 80.47%
- Precision: 80.12%
- Recall: 81.47%
Training History:
The training and validation curves show steady improvement and convergence, with minimal overfitting due to regularization.

Figure: Training and validation metrics over epochs.
Confusion Matrix:
The confusion matrix below visualizes the model's performance across all classes, highlighting areas of strong and weak classification.

Figure: Confusion matrix for test set predictions.
- Change
batch_size,img_size, or model architecture inmain.ipynbas needed. - Adjust augmentation pipeline for different image sizes or transformations.
If you use this project or dataset, please cite the UCI RealWaste dataset and this repository.