Skip to content

Repository files navigation

Wastewise 🗑️

An intelligent AI-powered waste classification system that helps users sort household waste by analyzing images of waste items. The system uses deep learning (ResNet50-based transfer learning) to classify waste into 12 categories with high accuracy and provides explainable classification results through an intuitive graphical interface.

Features

  • Image-based Waste Classification: Automatically classify household waste into 12 categories (batteries, biological waste, glass types, cardboard, clothes, metal, paper, plastic, shoes, and general trash)
  • PyQt5 GUI Interface: User-friendly graphical application for real-time image analysis
  • Transfer Learning Architecture: ResNet50 backbone with fine-tuning for optimal accuracy
  • Multi-stage Training: Warmup → Fine-tuning → Full training pipeline for robust model
  • Explainable Results: Displays confidence scores for each waste category
  • Bilingual Support: English and Russian labels (интерфейс поддерживает русский язык)
  • Data Augmentation: Robust training with rotation, shifts, zoom, and brightness adjustments
  • Class Weighting: Handles imbalanced datasets effectively

Project Structure

Wastewise/
├── README.md                      # Project documentation
├── LICENSE                        # License file
├── requirements.txt               # Python dependencies
├── config.py                      # Configuration parameters
│
├── model.py                       # ResNet50-based model architecture
├── train.py                       # Training pipeline (3-stage training)
├── evaluate.py                    # Model evaluation metrics
│
├── dataset.py                     # Data loading and augmentation utilities
├── interface.py                   # PyQt5 GUI application
│
├── data/
│   └── download_dataset.py        # Kaggle dataset downloader
│
├── utils/
│   └── callbacks.py               # Keras callbacks (checkpoint, early stopping, LR scheduling)
│
├── models/                        # Trained model weights (generated during training)
│   └── best_model.h5             # Best model checkpoint (downloaded from Google Drive)
│
├── test_image/                    # Sample images for testing
│   └── [test images]
│
└── __pycache__/                   # Python cache files

Waste Categories (12 Classes)

The model classifies waste into the following categories:

  1. Battery (Батарейки) - Electrical batteries and accumulators
  2. Biological (Органика) - Organic waste, food scraps
  3. Brown Glass (Коричневое стекло) - Brown/amber glass bottles
  4. Cardboard (Картон) - Cardboard boxes and packaging
  5. Clothes (Одежда) - Textile clothing and fabrics
  6. Green Glass (Зелёное стекло) - Green glass bottles
  7. Metal (Металл) - Metal containers and items
  8. Paper (Бумага) - Paper and cardstock
  9. Plastic (Пластик) - Plastic containers and items
  10. Shoes (Обувь) - Footwear
  11. Trash (Прочее) - General waste and mixed materials
  12. White Glass (Белое стекло) - Clear/white glass bottles

Installation

Prerequisites

  • Python 3.8 or higher
  • pip (Python package manager)

Step 1: Clone the Repository

git clone https://github.com/bakytbekovJ27/Wastewise.git
cd Wastewise

Step 2: Install Dependencies

python -m venv venv

# Windows (PowerShell):
venv\Scripts\activate.bat

# Linux / macOS:
source venv/bin/activate

pip install -r requirements.txt

This will install:

  • TensorFlow (≥2.16.2) - Deep learning framework
  • Keras (≥3.11.3) - Neural network API
  • NumPy (≥1.26.4) - Numerical computing
  • Scikit-learn (≥1.6.1) - Machine learning utilities
  • Pillow (≥11.3.0) - Image processing
  • PyQt5 (≥5.15.11) - GUI framework
  • kagglehub (≥0.4.1) - Kaggle dataset downloader

Step 3: Download Pre-trained Model

The trained model is available on Google Drive due to size constraints:

  1. Download the model from: Google Drive Link
  2. Place the downloaded best_model.h5 file in the models/ directory:
    Wastewise/models/best_model.h5
    

Usage

1. Running the GUI Application

python interface.py

This launches the PyQt5 graphical interface where you can:

  • Load an image from your computer
  • View the classified waste category
  • See confidence scores for all 12 categories
  • Display the image preview

2. Training the Model from Scratch

python train.py

The training process:

  • Automatically downloads the garbage classification dataset from Kaggle
  • Stage 1 - Warmup (10 epochs): Freezes ResNet50 backbone, trains only the classification head
    • Learning rate: 1e-3
  • Stage 2 - Fine-tuning (40 epochs): Unfreezes last 50 layers of ResNet50
    • Learning rate: 1e-4
    • Includes ModelCheckpoint, EarlyStopping, and ReduceLROnPlateau callbacks
  • Stage 3 - Full Training (20 epochs): Trains all layers end-to-end
    • Learning rate: 1e-5

Trained model checkpoints are saved to models/best_model.h5

3. Evaluating Model Performance

python evaluate.py

Generates:

  • Classification report (precision, recall, F1-score for each class)
  • Confusion matrix
  • Per-class performance metrics

Configuration

Edit config.py to adjust training parameters:

IMG_SIZE = (224, 224)           # Input image size for ResNet50
BATCH_SIZE = 32                 # Training batch size
VAL_SPLIT = 0.2                 # Validation split ratio (20%)

WARMUP_EPOCHS = 10              # Stage 1 epochs
FINETUNE_EPOCHS = 40            # Stage 2 epochs
FULL_EPOCHS = 20                # Stage 3 epochs

LR_WARMUP = 1e-3                # Warmup learning rate
LR_FINETUNE = 1e-4              # Fine-tuning learning rate
LR_FULL = 1e-5                  # Full training learning rate

MODEL_DIR = "outputs"           # Output directory for models

Architecture

Model Backbone

  • Base Network: ResNet50 pre-trained on ImageNet
  • Input: 224×224 RGB images
  • Output: 12-class probability distribution (softmax)

Classification Head

ResNet50 backbone
    ↓
GlobalAveragePooling2D
    ↓
BatchNormalization
    ↓
Dropout (0.5)
    ↓
Dense(512, relu) + L2 regularization
    ↓
BatchNormalization
    ↓
Dropout (0.3)
    ↓
Dense(12, softmax) [output]

Training Strategy

  • Transfer Learning: Leverages pre-trained ImageNet weights
  • Progressive Unfreezing: Gradually trains deeper layers
  • Data Augmentation: Rotation, shifts, zoom, brightness adjustments
  • Class Weighting: Handles imbalanced waste categories
  • Regularization: L2 weight penalty to prevent overfitting
  • Early Stopping: Prevents training on plateau with patience=10

Dataset

The project uses the Garbage Classification Dataset from Kaggle:

System Requirements

Minimum

  • CPU: 4-core processor
  • RAM: 8 GB
  • Storage: 5 GB (for dataset and models)

Recommended (for training)

  • GPU: NVIDIA GPU with CUDA support (e.g., GTX 1060 or better)
  • RAM: 16 GB
  • Storage: 10+ GB SSD

GPU Support

To enable GPU acceleration for training:

pip install tensorflow[and-cuda]

Troubleshooting

Issue: Model not found when running interface.py

Solution: Download the pre-trained model from Google Drive and place it in models/best_model.h5

Issue: Out of memory during training

Solution: Reduce BATCH_SIZE in config.py (try 16 or 8)

Issue: Slow training

Solution: Ensure GPU is available (nvidia-smi to check) or reduce dataset size

Issue: Kaggle API credentials error

Solution: Ensure kagglehub is properly configured with Kaggle API credentials

Performance

Model Metrics

Overall Accuracy

  • Test Set Accuracy: ~97.5%
  • Validation Set Accuracy: ~98.0%

Training Curves

The model demonstrates stable convergence with excellent performance:

Training Curves

  • Epoch Range: 70 epochs total (10 warmup + 40 fine-tuning + 20 full training)
  • Model Accuracy: Reaches ~98% at convergence
  • Model Loss: Converges to ~0.1
  • Validation Performance: Consistent improvement with minimal overfitting
  • Training Stability: Smooth curves indicate robust optimization

Per-Class Performance (Confusion Matrix)

Confusion Matrix

Classification Results by Waste Category:

Category True Positives Accuracy Notes
Battery (Батарейки) 181 98.4% Excellent recognition
Biological (Органика) 192 98.5% Highly accurate
Brown Glass (Коричневое стекло) 114 97.4% Good performance
Cardboard (Картон) 162 93.6% Some confusion with paper
Clothes (Одежда) 1054 99.1% Outstanding accuracy
Green Glass (Зелёное стекло) 118 96.7% Solid performance
Metal (Металл) 139 90.9% Minor misclassifications
Paper (Бумага) 202 96.7% Good differentiation
Plastic (Пластик) 151 88.3% Some overlap with other materials
Shoes (Обувь) 391 99.0% Excellent recognition
Trash (Прочее) 137 95.8% Reliable classification
White Glass (Белое стекло) 127 92.2% Good accuracy

Key Observations:

  • Clothes category shows exceptional accuracy (99.1%) with 1054 true positives
  • Shoes are also highly accurate (99.0%) with 391 correct classifications
  • Glass types show good differentiation despite similar visual properties
  • Slight confusion between cardboard and paper is expected due to material similarity
  • Overall model demonstrates robust waste classification across all categories

Inference Performance

  • Inference Time: ~100-200ms per image (CPU)
  • Throughput: 5-10 images per second (single CPU core)
  • GPU Inference: ~50-100ms per image (with NVIDIA GPU)

License

This project is licensed under the terms specified in the LICENSE file.

Contributing

Contributions are welcome! Please feel free to:

  1. Fork the repository
  2. Create a feature branch
  3. Commit your improvements
  4. Submit a pull request

Future Enhancements

  • Support for batch processing multiple images
  • Export to ONNX format for mobile deployment
  • Add uncertainty estimation for low-confidence predictions
  • Web interface (Flask/FastAPI)
  • Model quantization for edge devices
  • Integration with waste management systems

Acknowledgments

  • ResNet50 architecture from TensorFlow/Keras
  • Garbage classification dataset from Kaggle (mostafaabla)
  • PyQt5 for the GUI framework

About

An intelligent assistant that helps users sort household waste by analyzing images, explaining classification decisions, and reducing sorting errors.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages