Skip to content

SanyaShresta25/garbage-classification-using-cnn-alexnet

Repository files navigation

๐ŸŒŽ Garbage Classification CNN ๐Ÿ—‘๏ธ

Garbage Classification TensorFlow Accuracy

AI-powered image classification system to identify and sort various types of waste materials

๐Ÿ“ Overview

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.

โœจ Features

  • 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

๐Ÿ› ๏ธ Technical Architecture

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

๐Ÿ“Š Model Performance

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%

๐Ÿ”ง Installation & Setup

  1. Clone this repository:

    git clone https://github.com/SanyaShresta25/Garbage-Classification-Using-CNN-AlexNet.git
    cd Garbage_Classification_Using_CNN&AlexNet
    
  2. Install dependencies:

    pip install -r requirements.txt
    
  3. Prepare your dataset:

    • Organize images in folders named after each category
    • Default folder structure:
      Garbage classification/
      โ”œโ”€โ”€ cardboard/
      โ”œโ”€โ”€ glass/
      โ”œโ”€โ”€ metal/
      โ”œโ”€โ”€ paper/
      โ”œโ”€โ”€ plastic/
      โ””โ”€โ”€ trash/
      
  4. Configure settings in the script if needed:

    • Adjust IMAGE_SIZE, BATCH_SIZE, EPOCHS, etc.

๐Ÿš€ Usage

The script will:

  1. Load and preprocess the dataset
  2. Create data generators with augmentation
  3. Define and compile the CNN model
  4. Train until reaching 90% accuracy or the maximum epochs
  5. Save the trained model to garbage_classifier_model.h5
  6. Generate performance metrics and visualizations

Inference

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}")

๐Ÿ“‹ Dataset

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

    image

๐Ÿ” Model Evaluation

The model evaluation includes:

  • Confusion matrix visualization
  • Detailed classification report with precision, recall, and F1-score
  • Class-wise accuracy metrics
  • Hyperparameter tuning image

๐Ÿ›ฃ๏ธ Future Improvements

  • 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

๐Ÿค Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

๐Ÿ“ž Contact

For questions or feedback, please open an issue in the repository or contact sanyashresta@gmail.com.


Made with โค๏ธ for a cleaner planet

About

Deep learning-based garbage classification using a custom CNN in TensorFlow/Keras. ๐Ÿšฎ Classifies waste into 6 categories (cardboard, glass, metal, paper, plastic, trash) using data augmentation, batch normalization, and dropout.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors