--- title: Waste Classify emoji: 📈 colorFrom: green colorTo: red sdk: gradio sdk_version: 6.19.0 python_version: '3.13' app_file: app.py pinned: false license: apache-2.0 --- # Waste Classification – Organic vs Recyclable (VGG16) This repository contains two Keras/TensorFlow models for classifying images of waste into **Organic (O)** and **Recyclable (R)** categories. Both models are based on a pre‑trained VGG16 backbone, but they differ in the training approach: - **`O_R_tlearn_vgg16_final.keras`** – Feature‑extraction model: the VGG16 base is frozen and only the newly added dense layers are trained. - **`O_R_tlearn_fine_tune_vgg16_final.keras`** – Fine‑tuned model: after feature extraction, the last convolutional block of VGG16 is unfrozen and the whole network is trained further, yielding slightly better performance. **Inference is performed using the fine‑tuned model** (`...fine_tune...`), as it achieves the highest accuracy on the test set. --- ## Model Performance | Model | Test Accuracy | |--------------------------|---------------| | Feature Extraction | 80% | | **Fine‑tuned** (recommended) | **81%** | --- ## Files - `O_R_tlearn_vgg16_final.keras` – feature‑extraction model - `O_R_tlearn_fine_tune_vgg16_final.keras` – fine‑tuned model (used for predictions) --- ## How to Use ### 1. Load the Fine‑Tuned Model ```python import tensorflow as tf import numpy as np from tensorflow.keras.preprocessing.image import load_img, img_to_array model = tf.keras.models.load_model("O_R_tlearn_fine_tune_vgg16_final.keras") ``` ### 2. Preprocess an Image ```python IMG_SIZE = (150, 150) def preprocess_image(image_path): img = load_img(image_path, target_size=IMG_SIZE) img_array = img_to_array(img) img_array = img_array / 255.0 return np.expand_dims(img_array, axis=0) ``` ### 3. Make a Prediction ```python image_path = "path/to/your/waste_image.jpg" input_data = preprocess_image(image_path) prediction = model.predict(input_data) # Output class if prediction[0][0] < 0.5: print("Predicted: Organic (O)") else: print("Predicted: Recyclable (R)") ``` > **Note:** The model outputs a single sigmoid value. Values below 0.5 are classified as Organic, above as Recyclable. --- ## Training Details - Base model: VGG16 (weights = `imagenet`) - Input size: 150×150 pixels - Optimizer: RMSprop with learning rate decay - Loss: binary cross‑entropy - Early stopping and model checkpointing were used to prevent overfitting The dataset was split into training (80%) and validation (20%). Data augmentation (shifts, flips) was applied during training. --- ## Citation If you use this model, please cite this repository. --- ## License This model is released under the [MIT License](LICENSE). ```