Skip to content

Soritify is an AI based garbage classification software .It currently supports 12 classes of garbage images

Notifications You must be signed in to change notification settings

amodhyh/sortify

Repository files navigation

Garbage Classification Project

Overview

This project is a full-stack application for classifying garbage images into categories using deep learning. It combines a FastAPI backend (Python) with a React frontend for an interactive user experience.


Table of Contents


1. Features

  • Interactive Frontend: Responsive React UI for image upload, result visualization, and classification history chart. image image

  • Efficient Backend: FastAPI server serving predictions from a trained Keras CNN model.

  • Model Integration: Seamless use of TensorFlow/Keras models for real-time inference.

  • Classification History: Bar chart of previous classifications using localStorage.

  • Recyclability Status: Visual indication (logo, color) of whether the predicted class is recyclable.

  • PDF Report Generation: (Planned) Downloadable report of classification results.


2. Architecture

Frontend (React) <-> FastAPI Backend <-> Keras Model
                  |                |                  |
        User Uploads      Receives API      Model Predicts
        Image/Views UI    Requests/Results  Class & Probabilities

Data Flow

  1. User uploads an image via the frontend.
  2. Frontend sends the image to the FastAPI backend.
  3. Backend preprocesses the image and runs it through the CNN model.
  4. Backend returns the predicted class and probabilities.
  5. Frontend displays the result, recyclability status, and updates the classification history chart.

3. Project Structure

Project/
├── backend/
│   ├── main.py
│   ├── models/
│   └── util/
├── frontend/
│   ├── src/
│   │   ├── pages/
│   │   ├── components/
│   │   ├── services/
│   │   └── styles/
│   └── public/
├── data/
│   └── raw/
├── notebooks/
│   ├── preprocessing.ipynb
│   └── CNNModel.ipynb
├── requirements.txt
├── README.md
└── ...

4. Technologies Used

  • Backend: Python, FastAPI, TensorFlow/Keras
  • Frontend: React, Chart.js, react-chartjs-2, Vite
  • Other: Jupyter Notebooks, localStorage

5. Digital Image Processing Techniques

  • Image Resizing: All input images are resized to 224x224 pixels to match the input requirements of MobileNetV2.
  • Image Enhancement: CLAHE (Contrast Limited Adaptive Histogram Equalization) is applied to the luminance channel to improve contrast and detail.
  • Color Space Conversion: Images are converted from BGR to YCrCb for enhancement, then back to RGB for model input.
  • Normalization: Pixel values are scaled to the [0, 1] range for stable training.
  • Data Augmentation: Random rotations, flips, and other augmentations are applied to increase dataset diversity and reduce overfitting.
  • Label Encoding: Class labels are encoded using scikit-learn’s LabelEncoder for compatibility with Keras.

6. CNN Model Architecture & Training

  • Base Model: MobileNetV2 (pretrained on ImageNet, used as feature extractor)
    • Input shape: (224, 224, 3)
    • All layers frozen by default; optionally, last N layers can be unfrozen for fine-tuning.
  • Custom Head:
    • Global Average Pooling
    • Dropout (0.2)
    • Dense layer with softmax activation for multi-class classification
  • Training Details:
    • Optimizer: Adam
    • Loss: Categorical Crossentropy
    • Metrics: Accuracy, Precision, Recall, AUC, Top-3 Accuracy
    • K-Fold Cross Validation (5 folds) for robust evaluation
    • Early Stopping and ReduceLROnPlateau callbacks for efficient training
  • Ensemble: Final predictions can be made using a soft-voting ensemble of the best models from each fold.

7. Setup & Installation

Prerequisites

  • Python 3.11+
  • Node.js & npm

Backend Setup

  1. Navigate to the backend directory: bash cd backend
  2. Install Python dependencies: bash pip install -r ../requirements.txt
  3. Start the FastAPI server: bash uvicorn main:app --host localhost --port 8089 --reload

Frontend Setup

  1. Navigate to the frontend directory: bash cd frontend
  2. Install Node.js dependencies: bash npm install
  3. Start the React development server: bash npm run dev

8. Usage

  1. Open the frontend in your browser (usually at http://localhost:5173).
  2. Upload an image to classify.
  3. View the predicted class, recyclability status, and previous classification chart.
  4. (Optional) Download a PDF report of the result (if implemented).

9. Model Training & Evaluation

  • K-Fold Cross Validation: The dataset is split into 5 folds; each fold trains a fresh model and evaluates on its validation split.
    • Ensemble method with soft voting was used to get the final model combining all the best model from the cross validation folds.
  • Performance Metrics: Accuracy, precision, recall, AUC, and top-3 accuracy are tracked per fold.
  • Confusion Matrix: Visualized for overall and per-fold results to analyze misclassifications.
  • Learning Curves: Training and validation accuracy/loss curves are plotted for each fold and averaged.
  • Overall Results
Class Precision Recall F1-Score
battery0.950.930.94
biological0.990.980.98
brown-glass0.930.860.90
cardboard0.950.920.94
clothes0.990.980.99
green-glass0.970.910.94
metal0.890.810.85
paper0.920.940.93
plastic0.800.820.81
shoes0.970.990.98
trash0.900.960.93
white-glass0.770.890.83
accuracy0.92
macro avg0.920.920.92
weighted avg0.920.920.92
image

10. Contributing

Contributions are welcome! Please fork the repository and submit a pull request. For major changes, open an issue first to discuss what you would like to change.


11. License

This project is for educational purposes as part of the Digital Image Processing course.


About

Soritify is an AI based garbage classification software .It currently supports 12 classes of garbage images

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •