Skip to content

About

API service powered by TensorFlow that identifies whether waste is organic or recyclable based on image input. Built with Flask and ready for deployment.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 

Repository files navigation

Waste Classifier API

This Flask API provides image classification for waste types using a trained deep learning model. The API can classify waste images into two categories: Organic and Recyclable.

🚀 Features

  • Image Classification: Upload waste images and get predictions with confidence scores
  • Health Monitoring: Check API status and model availability
  • Class Information: Retrieve supported waste categories
  • Cross-Origin Support: CORS enabled for web applications
  • Error Handling: Comprehensive error responses and logging

📋 API Endpoints

POST /predict

Classify a waste image from Base64 encoded data.

Request Body:

{
  "image": "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQ..."
}

Response:

{
  "success": true,
  "result": {
    "class": "Recyclable",
    "confidence": 0.95,
    "all_predictions": {
      "Organic": 0.05,
      "Recyclable": 0.95
    }
  }
}

GET /health

Check API health status and model availability.

Response:

{
  "status": "healthy",
  "model_loaded": true
}

GET /classes

Get list of supported waste classes.

Response:

{
  "classes": ["Organic", "Recyclable"]
}

🛠️ Installation

  1. Clone the repository:

    git clone <repository-url>
    cd waste_classification_api
  2. Install dependencies:

    pip install flask flask-cors tensorflow numpy opencv-python pillow
  3. Ensure model file exists: Make sure waste_model.keras is in the project root directory.

  4. Run the application:

    python app.py

The API will be available at http://localhost:5000

📦 Dependencies

  • Flask: Web framework for the API
  • Flask-CORS: Cross-Origin Resource Sharing support
  • TensorFlow: Deep learning framework for model inference
  • NumPy: Numerical computing for array operations
  • OpenCV: Computer vision library for image processing
  • Pillow: Python Imaging Library for image handling

🔧 Model Information

  • Input Size: 224x224 pixels
  • Categories: Organic, Recyclable
  • Format: Keras model (.keras file)
  • Preprocessing: RGB conversion, resizing, normalization (0-1 range)

📝 Usage Examples

Using cURL:

curl -X POST http://localhost:5000/predict \
  -H "Content-Type: application/json" \
  -d '{"image": "data:image/jpeg;base64,<your-base64-image>"}'

Using Python requests:

import requests
import base64

# Read and encode image
with open('waste_image.jpg', 'rb') as f:
    image_data = base64.b64encode(f.read()).decode()

# Make prediction
response = requests.post('http://localhost:5000/predict', 
                        json={'image': f'data:image/jpeg;base64,{image_data}'})
result = response.json()
print(f"Prediction: {result['result']['class']} ({result['result']['confidence']:.2f})")

⚙️ Configuration

The API runs on:

  • Host: 0.0.0.0 (all interfaces)
  • Port: 5000
  • Debug: Disabled for production

🚨 Error Handling

The API returns appropriate HTTP status codes:

  • 200: Success
  • 400: Bad Request (missing image data)
  • 404: Endpoint not found
  • 500: Internal server error (model issues)

📊 Supported Image Formats

  • JPEG
  • PNG
  • Other PIL-supported formats
  • Base64 encoded images

🔍 Troubleshooting

  1. Model not loading: Ensure waste_model.keras exists in the project directory
  2. Import errors: Install all required dependencies
  3. Image processing errors: Check image format and Base64 encoding
  4. CORS issues: Flask-CORS is enabled by default

About

API service powered by TensorFlow that identifies whether waste is organic or recyclable based on image input. Built with Flask and ready for deployment.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages