Skip to content

Repository files navigation

image



🌿 Urban Leaf Health Monitoring

An end-to-end remote sensing & machine learning system for tracking urban vegetation health, land-use change, and ecological disturbances using multi-spectral satellite imagery.


License: MIT Python Next.js PyTorch TypeScript Google Earth Engine


πŸš€ Quick Start Β· 🌍 Study Regions Β· πŸ—οΈ Architecture Β· πŸ“Š Results Β· 🀝 Contributing


πŸ“– Table of Contents


🌟 About The Project

Urban Leaf Health Monitoring is a comprehensive, production-grade pipeline that leverages multi-spectral Sentinel-2 satellite imagery, deep learning, and an interactive Next.js web application to deliver actionable ecological intelligence for urban planning, conservation, and environmental monitoring.

The system solves a fundamental challenge in geospatial science:

How do we transform raw satellite data into a full machine-learning pipeline for pixel-level vegetation and disturbance segmentation at scale?

By integrating cloud-masked data ingestion from Google Earth Engine, a 14-channel Attention U-Net model, and a browser-based segmentation comparison tool, this project delivers a complete research-to-web workflow for monitoring forests, bushfire recovery, and urban encroachment across diverse geographic regions.


✨ Key Features

Feature Description
πŸ›°οΈ Multi-Spectral Ingestion Pulls 10 Sentinel-2 bands + 4 computed indices (NDVI, EVI, SAVI, BSI) via Google Earth Engine
☁️ Cloud-Masked Pipeline Strict QA60 cloud filtering ensures high-quality, cloud-free imagery
πŸ”¬ Attention U-Net 14-channel input, 5-class dense prediction with attention gates for selective focus
πŸ§ͺ Domain-Aware Augmentation Spectral jitter, random band dropout, spatial transforms β€” purpose-built for satellite imagery
⏱️ Temporal Analysis Multi-year and event-window comparisons (pre/during/post disturbance)
🌐 Interactive Web App Side-by-side model comparison lab built with Next.js, WebWorkers, and canvas rendering
πŸ–₯️ HPC-Ready Full PBS job scripts, environment setup, AMP training, and H100-optimized training loop
πŸ“¦ Dashboard-Ready Artifacts Inference exports segmentation masks, overlays, JSON summaries, and GeoTIFFs

πŸ–ΌοΈ Sandbox Previews

πŸ›°οΈ Region of Interest β€” Coordinate Selection

ROI Selection

Defining geographic bounding boxes for the Hasdeo study area inside Google Earth Engine.


☁️ Cloud Masking β€” Before & After

image

Applying QA60 cloud and cirrus masking ensures downstream vegetation analysis is not polluted by cloud shadows.


πŸ“‰ Vegetation Degradation β€” NDVI Analysis

image

NDVI-based degradation visualization exposing deforestation signals in the Hasdeo Forest between 2018–2023.


πŸ“ˆ Year-Wise Comparison Results

image Β  Class Separability

(Top) Cumulative forest loss chart across the Hasdeo timeline. (Bottom) Class separability matrix validating spectral feature quality.


πŸ› οΈ Tech Stack

🌐 Web Application

Technology Purpose
Next.js Next.js 14 App Router, API routes, file serving
React React 18 Component model, hooks, transitions
TypeScript TypeScript 5.5 Full type safety across the web layer
πŸ•ΈοΈ Web Workers Background thread pixel classification β€” UI stays responsive
🎨 Canvas API Client-side mask rendering and overlay compositing
Lucide Lucide React Icon system

🐍 ML & Geospatial Pipeline

Technology Purpose
PyTorch PyTorch 2.2+ Attention U-Net training, AMP, GradScaler
Google Earth Engine Earth Engine API Sentinel-2 data export, cloud filtering
πŸ—ΊοΈ Rasterio + GDAL GeoTIFF I/O, spatial referencing
🌐 GeoPandas + Shapely Vector geometry, AOI manipulation
πŸ”¬ Albumentations Augmentation pipeline (spatial + spectral)
πŸ–ΌοΈ OpenCV (headless) Image transforms, mask processing
πŸ“ NumPy + Pandas Patch arrays, statistics, CSV processing
πŸ€– Scikit-Learn Baseline models (SVM, Random Forest)
πŸ—ΊοΈ geemap Earth Engine visualization
πŸ“Š Matplotlib Plot generation and reporting

πŸ—οΈ Architecture & Pipeline

The backend follows a clean 6-phase pipeline, each encapsulated in its own module:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                     Urban Leaf ML Pipeline                          β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€  β”‚
β”‚  Phase 1  β”‚ Data Collection β”‚ GEE β†’ 10 bands + 4 indices β†’ GeoTIFF β”‚
β”‚  Phase 2  β”‚ Preprocessing   β”‚ Patch extraction (256Γ—256, stride 128)β”‚
β”‚  Phase 3  β”‚ Augmentation    β”‚ Spatial + Spectral (SpectralJitter,   β”‚
β”‚           β”‚                 β”‚ RandomBandDrop, flips, noise)         β”‚
β”‚  Phase 4  β”‚ Model           β”‚ Attention U-Net (14ch in, 5-class out)β”‚
β”‚  Phase 5  β”‚ Training        β”‚ AMP, Cosine LR, Combined Dice+CE Loss β”‚
β”‚  Phase 6  β”‚ Inference       β”‚ Tiled prediction β†’ mask/overlay/JSON  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

🧠 Model β€” Attention U-Net

Input: (B, 14, 256, 256)  ← 10 Sentinel-2 bands + NDVI, EVI, SAVI, BSI

Encoder:  DoubleConv β†’ Down β†’ Down β†’ Down β†’ Down (bottleneck)
Decoder:  Up + AttentionGate Γ— 4
Output:   (B, 5, 256, 256)  ← 5 land-cover classes

5 Output Classes:

  1. 🌳 Vegetation
  2. 🌾 Sparse Vegetation
  3. 🟫 Bare Soil / Rock
  4. πŸ™οΈ Built-up / Urban
  5. πŸ’§ Water / Shadow

Loss: 50% CrossEntropy + 50% Dice Loss β€” balances pixel accuracy with region-overlap quality.


🌍 Study Regions

Region Focus Time Range
🌲 Hasdeo Forest, India Mining-driven deforestation, NDVI degradation signals 2018 – 2024
πŸ™οΈ Sydney Blue Mountains Fringe, AU Urban expansion, ecological boundary shifts Multi-year
πŸ”₯ Kangaroo Island, AU Black Summer bushfire impact & post-fire recovery 2020 – 2021

πŸ“ Project Structure

Urban-Leaf-Health-Monitoring/
β”‚
β”œβ”€β”€ πŸ“ app/                             # Next.js 14 Web Application
β”‚   β”œβ”€β”€ segmentation-lab/               # Side-by-side segmentation comparison UI
β”‚   β”‚   β”œβ”€β”€ page.tsx                    # Main page with upload, sample selector, KPIs
β”‚   β”‚   └── segmentation.worker.ts      # Web Worker β€” runs pixel classification off main thread
β”‚   β”œβ”€β”€ hypothesis/                     # Hypothesis/analysis pages
β”‚   β”œβ”€β”€ recommendation/                 # Recommendation pages
β”‚   β”œβ”€β”€ api/                            # Next.js API routes (asset serving)
β”‚   β”œβ”€β”€ globals.css                     # Global CSS design system
β”‚   └── layout.tsx                      # Root layout
β”‚
β”œβ”€β”€ πŸ“ h100_config/                     # Core ML Pipeline (HPC-ready)
β”‚   β”œβ”€β”€ 01_data_collection.py           # GEE Sentinel-2 data collection
β”‚   β”œβ”€β”€ 02_preprocessing.py             # Patch extraction, normalization
β”‚   β”œβ”€β”€ 03_augmentation.py              # Spatial + spectral augmentation
β”‚   β”œβ”€β”€ 04_model.py                     # Attention U-Net architecture + losses
β”‚   β”œβ”€β”€ 05_train.py                     # Training loop (AMP, checkpointing)
β”‚   β”œβ”€β”€ 06_predict_visualize.py         # Inference, mask/overlay export
β”‚   β”œβ”€β”€ setup_env.sh                    # HPC environment setup
β”‚   β”œβ”€β”€ job_cpu.pbs                     # PBS CPU job script
β”‚   β”œβ”€β”€ job_gpu.pbs                     # PBS GPU job script
β”‚   └── LOCAL_TEST.py                   # Local pipeline test runner
β”‚
β”œβ”€β”€ πŸ“ scripts/                         # Research Notebooks & Analysis
β”‚   β”œβ”€β”€ 01_area_of_interest_selection/  # ROI selection notebooks
β”‚   β”œβ”€β”€ 02_comparison_based_on_events/  # Event-window comparison (bushfire, mining)
β”‚   β”œβ”€β”€ 03_comparison_based_on_years/   # Multi-year temporal analysis
β”‚   β”œβ”€β”€ 04_data_agumentation/           # Augmentation experiments
β”‚   └── 05_data_modelling/              # Model training notebooks
β”‚
β”œβ”€β”€ πŸ“ data/                            # Earth Engine exports & datasets
β”‚   β”œβ”€β”€ 01_area_of_interest_selection_using_sampling/
β”‚   β”‚   β”œβ”€β”€ batch_1/                    # Hasdeo Forest dataset
β”‚   β”‚   β”œβ”€β”€ batch_2/                    # Sydney Blue Mountains dataset
β”‚   β”‚   └── batch_3/                    # Kangaroo Island dataset
β”‚   └── 02_comparison_based_on_events/
β”‚       β”œβ”€β”€ event_1/                    # Hasdeo event CSVs and TIFF exports
β”‚       └── event_2/                    # Additional event data
β”‚
β”œβ”€β”€ πŸ“ assets/                          # Visualizations & project media
β”‚   β”œβ”€β”€ plots/                          # Result plots (plot_1.png … plot_10.png)
β”‚   β”œβ”€β”€ year_wise_comparison/           # Year-over-year forest change charts
β”‚   β”œβ”€β”€ presentation_images/            # Key images (NDVI, cloud removal, ROI)
β”‚   └── ppts/                           # Presentation PDFs
β”‚
β”œβ”€β”€ πŸ“ docs/                            # Technical documentation
β”‚   β”œβ”€β”€ Urban_Leaf_Model_Pipeline_Guide.md
β”‚   └── Urban_Leaf_Web_Project_Guide.md
β”‚
β”œβ”€β”€ package.json                        # Node.js dependencies
β”œβ”€β”€ requirements.txt                    # Python dependencies
β”œβ”€β”€ next.config.mjs                     # Next.js configuration
β”œβ”€β”€ tsconfig.json                       # TypeScript configuration
└── README.md

πŸš€ Quick Start

Prerequisites

  • Node.js 18+ β€” for the web application
  • Python 3.9+ β€” for the ML pipeline
  • pip / conda β€” for Python dependency management
  • Google Earth Engine account β€” for data collection

1️⃣ Clone the Repository

git clone https://github.com/vijaysolanki9079/Urban-Leaf-Health-Monitoring.git
cd Urban-Leaf-Health-Monitoring

2️⃣ ML Pipeline Setup

# Install Python dependencies
pip install -r requirements.txt

# Authenticate with Google Earth Engine
earthengine authenticate

3️⃣ Web Application Setup

# Install Node.js dependencies
npm install

# Run the development server
npm run dev

Open http://localhost:3000 to view the Segmentation Lab and interactive comparison tools.


🌐 Web Application

The web application provides an interactive Segmentation Comparison Lab that:

  • πŸ“€ Accepts user-uploaded PNG / JPEG / WebP images (up to 30 MB)
  • πŸ”„ Runs two segmentation engines simultaneously in a dedicated Web Worker (keeps the UI fully responsive)
  • 🎨 Renders colour-coded segmentation masks and overlays using the Canvas API
  • πŸ“Š Displays class distribution bars and 4 derived scene indicators β€” Canopy Cover, Built-up Share, Exposed Surface, Water/Shadow
  • πŸ–ΌοΈ Includes 3 preloaded sample scenes from the Hasdeo and Kangaroo Island datasets
npm run dev        # Development server (hot reload)
npm run build      # Production build
npm run lint       # ESLint check
npm run typecheck  # TypeScript type check

πŸ–₯️ HPC Training Workflow

For running the model training pipeline on an HPC cluster (PBS/Slurm):

cd h100_config

# 1. Set up the environment
bash setup_env.sh

# 2. Submit CPU preprocessing job
qsub job_cpu.pbs

# 3. Submit GPU training job
qsub job_gpu.pbs

Manual training and inference:

# Train the Attention U-Net
python h100_config/05_train.py \
  --data-dir /path/to/augmented \
  --model-dir /path/to/models \
  --results-dir /path/to/results

# Run inference & export visualizations
python h100_config/06_predict_visualize.py \
  --checkpoint /path/to/models/best_model.pth \
  --input /path/to/processed \
  --output-dir /path/to/results/inference

Training outputs:

  • best_model.pth β€” best checkpoint by validation mIoU
  • training_history.json / .csv β€” full loss/metric history
  • pseudo_label_distribution.json β€” class imbalance report
  • *.png overlays, *.tif masks, *.json summaries from inference

H100 optimizations enabled:

  • βœ… TF32 matmul & cuDNN
  • βœ… cuDNN benchmark mode
  • βœ… AMP with GradScaler
  • βœ… Gradient accumulation & clipping
  • βœ… Cosine annealing LR schedule

πŸ“Š Evaluation Metrics

Metric Type Purpose
mIoU Segmentation Mean Intersection over Union β€” primary quality metric
Dice Coefficient Segmentation Region-overlap quality across all classes
Pixel Accuracy Classification Fraction of correctly classified pixels
Precision / Recall Classification Per-class accuracy analysis
Confusion Matrix Classification Full inter-class error breakdown
Land-cover loss % Temporal Quantitative deforestation / recovery tracking

πŸ—ΊοΈ Roadmap

βœ… Phase 1: Data Engineering

  • GEE-based Sentinel-2 data collection
  • Cloud masking & valid-pixel filtering
  • Patch extraction & radiometric normalization
  • Spectral augmentation pipeline
  • Full local sync of 1,000+ Hasdeo GeoTIFF files

βœ… Phase 2: Core Analytics

  • Spectral indices: NDVI, EVI, SAVI, BSI, NBR
  • Attention U-Net implementation
  • AMP training with checkpointing and resume
  • Expert ground-truth masks & final benchmark metrics

βœ… Phase 3: Temporal & Event Analysis

  • Hasdeo mining event comparison (2022 window)
  • Monthly/seasonal time-series exports
  • Inference masks, overlays, GeoTIFFs & JSON summaries
  • Live checkpoint integration into web segmentation page

🀝 Contributing

Contributions are very welcome! Whether it's selecting new study regions, improving the augmentation pipeline, or enhancing the web UI β€” feel free to get involved.

  1. Fork the repository
  2. Create your feature branch: git checkout -b feature/your-feature
  3. Commit your changes: git commit -m 'feat: add your feature'
  4. Push to the branch: git push origin feature/your-feature
  5. Open a Pull Request

πŸ“„ License

This project is licensed under the MIT License β€” see the LICENSE file for details.

MIT License

Copyright (c) 2026 Vijay Solanki

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

Made with 🌿 by Vijay Solanki

⭐ Star this repository if you found it useful!