Show HN: Waste managment optimization with detectron2 and flask

13 hours ago 2

Waste Management Optimizer is a web application designed to plan and visualize optimized waste collection routes. It uses geospatial tools, real-time height data, and a sleek UI to support environmentally conscious waste disposal. Photo of overall elements

Mobile-app Guide Rasperry pi

 MIT Python 3.8+ Flask Detectron2

screenshot

This is a project that can be used to manage waste by combining IoT, Digital-platforms and AI. This improves the planning and monitoring of waste in a city with optimized routes, reports from citizens and even gas detection for bins containing dangerous material. This allows the trash collectors to be able to categorize the wastes

┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐ │ Web Frontend │ │ Flask Backend │ │ AI Detection │ │ │ │ │ │ │ │ • Leaflet Maps │◄──►│ • Route Engine │◄──►│ • Detectron2 │ │ • TailwindCSS │ │ • API Gateway │ │ • OpenCV │ │ • Interactive │ │ • Auth System │ │ • PyTorch │ │ • Jinja2 │ │ • Database │ │ • Image Proc │ └─────────────────┘ └─────────────────┘ └─────────────────┘ │ │ │ └───────────────────────┼───────────────────────┘ │ ┌─────────────────▼─────────────────┐ │ External APIs │ │ │ │ • OpenRouteService (Routing) │ │ • OpenStreetMap (Base Maps) │ │ • HeightAPI (Elevation Data) │ └───────────────────────────────────┘
  • Geospatial Intelligence: Leverages OpenRouteService for multi-point optimization
  • Computer Vision: Detectron2 framework for accurate dumpsite detection
  • Interactive Mapping: Real-time visualization using Leaflet.js
  • Database Integration: SQLite for user management and location storage
  • Dumpsite Recognition: Automated detection using trained Detectron2 models
  • Image Processing: OpenCV integration for preprocessing and analysis
  • Custom Training: Ability to retrain models with new datasets

Advanced Route Optimization

  • Multi-point Routing: Optimized paths through multiple collection points
  • Walking Route Planning: Foot-walking profile optimization
  • Real-time Calculations: Distance and time estimation
  • Interactive Visualization: Dynamic map updates with route overlays
  • Responsive Design: TailwindCSS for mobile-first approach
  • Interactive Maps: Leaflet.js with custom markers and layers
  • User Authentication: Secure login system with Flask sessions
  • Database Integration: Location and sensor data management
Component Technology Purpose
Frontend HTML5, TailwindCSS, Leaflet.js Interactive user interface
Backend Flask (Python), Jinja2 Web framework and templating
AI/ML Detectron2, PyTorch, OpenCV Computer vision and detection
Geospatial OpenRouteService API Routing and optimization
Mapping OpenStreetMap, Leaflet tiles Base mapping services
Database SQLite Data persistence
Authentication Flask Sessions, Werkzeug Security User management
Environment Python 3.8+, Virtual Environment Development setup
  • Python 3.8 or higher
  • Git
  • Virtual environment support
  • Internet connection for API access
git clone https://github.com/mtendekuyokwa19/gaiathon.git cd gaiathon
# Create virtual environment python3 -m venv .venv # Activate virtual environment # On Linux/macOS: source .venv/bin/activate # On Windows: # .venv\Scripts\activate
# Install project dependencies pip install . # Install Detectron2 (from source) pip install git+https://github.com/facebookresearch/detectron2.git

4. Environment Configuration

======= pip install .

```env ORS_API_KEY=your_openrouteservice_api_key

Setting Up Detectro with Flask

This project integrates the Detectron2 object detection framework into a Flask web application for detecting dumpsites. If you're cloning this repository for the first time, follow the steps below to set up your environment.

Detectron2 must be installed from source:

pip install git+https://github.com/facebookresearch/detectron2.git

Ensure your system meets the requirements for PyTorch and OpenCV.

5. Dataset and model setup

# OpenRouteService API Configuration ORS=your_openrouteservice_api_key # Flask Configuration FLASK_ENV=development FLASK_DEBUG=True SECRET_KEY=your_secret_key_here

Note: Get your free OpenRouteService API key from heigit.org

# Ensure images have consistent dimensions python resize.py

Edit the pathway inside resize.py if your data is in a different location.

# Train the Detectron2 model python train.py

This will create an output/ folder in detectron. Move it to the upper layer of the folder so that Flask can easily access it.

Important:

  • The trained model weights (model_final.pth) are not included due to GitHub's 100MB limit
  • You'll need to train the model or obtain pre-trained weights
  • Ensure your dataset follows COCO-style annotations
  • use of sqlite-cloud to allow communication between the IoT bins , webapp and Mobile-app
# Start the Flask development server flask --app flaskr run --debug

Navigate to http://127.0.0.1:5000 to access the application.

  1. Authentication: Register or login to access the system
  2. Dashboard: Access the main dashboard with navigation options
  3. Route Planning: Automatic route generation from database locations via /get_locations
  4. Dumpsite Detection: Upload satellite images for AI-powered analysis
  5. Data Management: View reports, sensor data, and location information
  • /auth/register - User registration
  • /auth/login - User authentication
  • /get_locations - Automatic route from database locations
  • /dumpsite - AI-powered dumpsite detection
  • /report - View system reports
  • /sensor - Monitor sensor data
  • /locations - Manage location data

Route Optimization Endpoints

Automatic Route Generation

Returns: HTML template with route visualization using Jinja2 templating

POST /dumpsite Content-Type: multipart/form-data file=<image_file>

Returns: HTML template with detection results rendered via Jinja2

Data Management Endpoints

Returns: HTML template with database reports using Jinja2

Returns: HTML template displaying sensor information

Returns: HTML template with location data from database

Note: All endpoints return HTML responses rendered through Jinja2 templating engine, not JSON APIs.

This project fulfills all competition requirements:

gaiathon/ ├── README.md # This comprehensive documentation ├── pyproject.toml # Project configuration and dependencies ├── flaskr/ # Main Flask application │ ├── auth.py # Authentication system │ ├── dashboard.py # Main application logic │ └── db.py # Database operations ├── detectro/ # AI detection components ├── static/ # Frontend assets (CSS, JS, images) ├── templates/ # HTML templates with Jinja2 ├── uploads/ # File upload directory ├── train.py # Model training script ├── resize.py # Image preprocessing utility └── output/ # Model weights and results
  • Deployment: Fully functional web application
  • Features: All core functionality implemented and tested
  • Database: SQLite integration for data persistence
  • Authentication: Secure user management system
  • Implementation: Complete Flask application with AI integration
  • Database Schema: User management and location storage
  • API Design: Flask endpoints with HTML responses
  • Testing: Functional application ready for deployment
  • Database Migration: PostgreSQL with PostGIS for production
  • API Enhancement: JSON API endpoints alongside HTML responses
  • Performance Optimization: Caching and query optimization

This project is licensed under the MIT License - see the LICENSE file for details.


Project Repository: https://github.com/mtendekuyokwa19/gaiathon
Built for sustainable waste management and environmental protection

Read Entire Article