ChangeFormer / README.md
manuelhorveydaniel's picture
Fix metadata formatting for Hugging Face
baa497b verified
---
license: mit
language: en
tags:
- change-detection
- satellite-imagery
- deforestation
- transformer
- gradio
- final-year-project
datasets:
- sentinel-2
model-index:
- name: ChangeFormer
results:
- task:
type: image-segmentation
name: Change Detection
dataset:
name: Brazilian Amazon (2020–2021)
type: remote-sensing
metrics:
- type: f1
value: 0.9986
- type: iou
value: 0.9972
---
# 🛰️ Deforestation Detection App
This application uses a transformer-based **ChangeFormer** model to detect deforestation in the Brazilian Amazon using Sentinel-2 satellite imagery. Developed as a final year project, it processes 4-band (RGB + NIR) `.tif` images from 2020 and 2021 to generate binary change masks and overlay predictions, achieving an **F1-score of 0.9986** and **IoU of 0.9972** on validation data.
---
## 🌍 Overview
- **Model**: Custom `ChangeFormer` with a Vision Transformer encoder, Feature Difference Module, and Deconv Decoder.
- **Data**: Sentinel-2 Level-2A imagery (10m resolution) and PRODES deforestation labels.
- **Interface**: Gradio-powered app for drag-and-drop uploads and real-time visualization.
- **Purpose**: Scalable and interpretable tool for land monitoring, policy-making, and conservation.
---
## ✨ Features
- Upload two `.tif` images (2020 and 2021) with 4 bands: B2 (blue), B3 (green), B4 (red), and B8 (NIR).
- Outputs:
- ✅ Raw RGB base image (2021)
- ✅ Binary change mask (black/white)
- ✅ RGB + red overlay for deforested regions
- ✅ Comment on % of detected change
- Handles large images with patch-based tiling, normalization, and stitching.
---
## ⚙️ Setup & Usage
### 🔧 Prerequisites
- Python 3.8+
- Required libraries: `torch`, `torchvision`, `timm`, `rasterio`, `numpy`, `pillow`, `gradio`
### 📦 Installation
```bash
git clone https://github.com/manuelhorvey/ChangeFormer.git
cd ChangeFormer
pip install -r requirements.txt
````
Place your trained model checkpoint as:
```
models/best_model.pth
```
### 🚀 Run Locally
```bash
python app.py
```
Then open: [http://localhost:7860](http://localhost:7860)
---
## 🧪 Input & Output
### Input
* Two 4-band `.tif` images from the same area:
* One from 2020
* One from 2021
* Patches preferred (e.g., 256×256)
### Output
* RGB image from 2021
* Red-highlighted deforestation overlay
* Binary change mask
* Textual feedback on % change
> ☁️ *Images with <20% cloud cover yield best accuracy.*
---
## 📊 Project Details
| Item | Value |
| ----------------- | ---------------------------------------------------- |
| **Region** | Brazilian Amazon (e.g., APA Triunfo do Xingu) |
| **Dataset Size** | 19,560 patches (256×256), 4 channels, 2 years |
| **Metrics** | F1-score: 0.9986, IoU: 0.9972 |
| **Augmentations** | Rotations (90/180/270), flips |
| **Future Plans** | Web-based monitoring alerts, SAR fusion, forecasting |
---
## 👥 Authors
* Emmanuel Amey
* Sammuel Young Appiah
* Asare Prince Owusu
* Yaaya Pearl Apenu
> Based on ideas from Alshehri et al. (2024), IEEE GRSL.
---
## 🪪 License
This project is licensed under the MIT License.
````
---