This Streamlit web application allows users to classify images of waste into two categories: Organic or Recyclable. It leverages a pre-trained TensorFlow/Keras deep learning model to provide real-time predictions directly in your browser, either through image upload or live camera feed.
- Dual Input Modes: Seamlessly switch between uploading an image file (JPG, JPEG, PNG, WEBP) or capturing a live picture using your device's camera.
- Instant Classification: Get immediate predictions (Organic or Recyclable) with a confidence score.
- Dynamic UI: The prediction section automatically clears when you switch between input methods, ensuring a clean user experience.
- Clear Camera Image: A dedicated button to clear the captured camera image and reactivate the camera.
- Simple Interface: Built with Streamlit for an intuitive and user-friendly web interface.
Follow these steps to get the app running on your local machine.
- Python 3.8+
- pip (Python package installer)
git clone https://github.com/Roshians/Waste-Classification.git
cd Waste-Classificationpython -m venv venv
# On Windows
.\venv\Scripts\activate
# On macOS/Linux
source venv/bin/activatepip install -r requirements.txtrequirements.txt content:
tensorflow==2.19.0
streamlit==1.45.1
numpy==2.1.3
pillow==11.1.0
Ensure your pre-trained Keras model file (best_model.h5) is in the same directory as app.py.
If your model is elsewhere, update the MODEL_PATH variable in app.py accordingly.
streamlit run app.pyThis command will open the Streamlit app in your default web browser.
This application uses a deep learning model based on the MobileNetV2 architecture to perform waste classification.
- Base Model: MobileNetV2, a lightweight and efficient convolutional neural network designed for mobile and embedded vision applications.
- Model File:
best_model.h5 - Image Size: Resized to (128, 128) pixels (
IMAGE_SIZE) - Normalization: Pixel values are divided by
255.0(RESCALE_FACTOR) to scale them to the 0–1 range. - Classes:
Recyclable(Assumed index 0)Organic(Assumed index 1)
⚠️ Note: The prediction logic inapp.pyassumespredictions[0][0]is the probability for 'Recyclable'. If your model's output order differs, adjust thepredicted_class_indexlogic accordingly.
-
Launch the app:
streamlit run app.py
-
Choose Input Method:
- "Upload Image" or
- "Use Camera" (via radio buttons)
-
Provide Image:
- Upload Image: Click "Choose an image..." and select a file.
- Use Camera: Click "Take a picture" to capture via webcam.
-
View Prediction:
- The app classifies the image and displays the predicted category with a confidence score.
-
Reset:
- Switching input methods automatically clears the image and prediction.
- Use "Clear image" in camera mode to retake a picture.
Pull requests are welcome! If you find bugs or have improvements in mind:
- Fork the repository
- Create a feature branch
- Commit your changes
- Open a pull request
This project is released into the public domain under The Unlicense.
- Built and Hosted with Streamlit
- Waste Classification Dataset on Kaggle