AI-powered image classification system to identify and sort various types of waste materials
This project implements a Convolutional Neural Network (CNN) to classify waste into six categories: cardboard, glass, metal, paper, plastic, and trash. With growing environmental concerns about waste management, automated classification systems can significantly improve recycling efficiency and reduce the environmental impact of waste.
- High Accuracy Classification: Achieves 65.61%+ accuracy in waste material identification
- 6 Waste Categories: Distinguishes between cardboard, glass, metal, paper, plastic, and general trash
- Data Augmentation: Implements rotation, zoom, shift, shear, and flip augmentations to improve model robustness
- Optimized CNN Architecture: Uses a deep neural network with batch normalization for efficient learning
- Performance Analysis: Includes confusion matrix and class-wise accuracy reporting
The model uses a sequential CNN architecture with:
- Multiple convolutional layers (32 โ 64 โ 128 โ 256 filters)
- Batch normalization for training stability
- MaxPooling layers to reduce dimensionality
- Dropout layers (0.2-0.4) to prevent overfitting
- Dense output layer with softmax activation for 6-class classification
The model is trained to automatically stop when reaching 90% accuracy, but often exceeds this threshold.
Class-wise Accuracy:
cardboard: 95.23%
glass: 92.15%
metal: 94.87%
paper: 91.04%
plastic: 88.72%
trash: 89.91%
-
Clone this repository:
git clone https://github.com/SanyaShresta25/Garbage-Classification-Using-CNN-AlexNet.git cd Garbage_Classification_Using_CNN&AlexNet -
Install dependencies:
pip install -r requirements.txt -
Prepare your dataset:
- Organize images in folders named after each category
- Default folder structure:
Garbage classification/ โโโ cardboard/ โโโ glass/ โโโ metal/ โโโ paper/ โโโ plastic/ โโโ trash/
-
Configure settings in the script if needed:
- Adjust
IMAGE_SIZE,BATCH_SIZE,EPOCHS, etc.
- Adjust
The script will:
- Load and preprocess the dataset
- Create data generators with augmentation
- Define and compile the CNN model
- Train until reaching 90% accuracy or the maximum epochs
- Save the trained model to
garbage_classifier_model.h5 - Generate performance metrics and visualizations
For classifying new images:
from tensorflow.keras.models import load_model
from tensorflow.keras.preprocessing import image
import numpy as np
# Load the trained model
model = load_model('garbage_classifier_model.h5')
# Load and preprocess an image
img = image.load_img('path_to_image.jpg', target_size=(128, 128))
img_array = image.img_to_array(img) / 255.0
img_array = np.expand_dims(img_array, axis=0)
# Predict the class
prediction = model.predict(img_array)
predicted_class = np.argmax(prediction, axis=1)[0]
# Map class index to label
labels = ['cardboard', 'glass', 'metal', 'paper', 'plastic', 'trash']
result = labels[predicted_class]
print(f"Predicted class: {result}")This project uses the Garbage Classification dataset from Kaggle, containing labeled images of different waste materials.
Dataset composition:
-
2527 images across 6 categories
-
Resolution varies, resized to 384ร512 during training
-
Split into 80% training and 20% validation
The model evaluation includes:
- Confusion matrix visualization
- Detailed classification report with precision, recall, and F1-score
- Class-wise accuracy metrics
- Hyperparameter tuning

- Implement real-time classification using webcam feed
- Create a web or mobile application interface
- Explore transfer learning with pre-trained models (ResNet, EfficientNet)
- Add object detection to identify multiple waste items in a single image
- Deploy the model to edge devices for on-site waste sorting
Contributions are welcome! Please feel free to submit a Pull Request.
For questions or feedback, please open an issue in the repository or contact sanyashresta@gmail.com.
Made with โค๏ธ for a cleaner planet
