How tushar-surti/building-detection-app works
Project Type and Purpose
• This is a full-stack web application built with Flask for detecting buildings in satellite/aerial images.
• The front end is a lightweight HTML/CSS/JavaScript interface; the back end handles image uploads, invokes a PyTorch DeepLab V3+ segmentation model, post-processes the output, and returns results.
File Structure Analysis
• Root files:
• app.py – Flask routes (controllers) and HTTP API endpoints (/, /upload, /about, /health).
• model.py – Model-loading and inference logic.
• Dockerfile, render.yaml – Containerization and deployment configurations.
• requirements.txt – Python dependencies.
• Directories:
• models/ – Pretrained model weights and metadata.
• templates/ – Jinja2 HTML templates (views).
• static/ – Client assets (JavaScript, CSS) and runtime file storage:
– uploads/ for incoming user images
– results/ for generated masks and overlays
README Insights
• Technology Stack: Flask, PyTorch/TorchVision, OpenCV, Pillow, NumPy, vanilla JS.
• Workflow steps: preprocessing → model inference (DeepLab V3+ with ASPP) → postprocessing (threshold & overlay) → visualization & statistics.
• API spec provided, sample response schema, and performance metrics.
Main Components
a. User Browser (UI Layer)
• Upload form, drag & drop, result display pages (index.html, about.html)
b. Flask Backend
• HTTP server (app.py)
• API endpoints
• Controller logic for routing, invoking model.py
c. Model Inference Pipeline
• Preprocessing module (resize, normalize)
• DeepLab V3+ model (PyTorch)
• Postprocessing module (threshold, mask generation, overlay)
• Statistics computation
d. File Storage
• Static/uploads for input
• Static/results for output
• models/ folder for weights
e. Optional Infrastructure
• Docker container (Dockerfile, .dockerignore)
• Deployment config (render.yaml)
Relationships and Data Flows
• Browser → HTTP POST /upload → Flask app → preprocess → model inference → postprocess → save results → HTTP JSON response → browser renders results.
• The health check endpoint monitors backend status.
• Template rendering for GET / and /about serve static HTML.
• Docker container encapsulates the entire back end + model environment.
Architectural Patterns & Design Principles
• MVC-inspired:
• Model: model.py + pretrained weights
• View: templates/ + static assets
• Controller: app.py routes
• Separation of concerns: UI, API, ML logic, and storage are distinct.
• Stateless HTTP handling; persistent storage on disk for images.
• Containerization for reproducibility.