ojasrohatgi commited on
Commit
4694583
Β·
verified Β·
1 Parent(s): 90239ec

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +232 -7
README.md CHANGED
@@ -1,11 +1,236 @@
1
  ---
2
- title: Deforestation Detection
3
- emoji: 😻
4
- colorFrom: green
5
- colorTo: yellow
6
  sdk: docker
7
- pinned: false
8
- license: mit
9
  ---
 
10
 
11
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ license: apache-2.0
 
 
 
3
  sdk: docker
4
+ pinned: true
5
+ short_description: Detect deforestation from satellite imagery.
6
  ---
7
+ # 🌳 Deforestation Detection using Satellite Imagery
8
 
9
+ This project aims to **detect deforestation from satellite images** using a **U-Net deep learning model**. It leverages automated satellite data collection, image segmentation techniques, and Earth Engine + TensorFlow pipelines to help environmental organizations monitor illegal deforestation in near real-time.
10
+
11
+ <p align="center">
12
+ <img src="Final Output.png" width="70%"/>
13
+ </p>
14
+
15
+ ---
16
+
17
+ ## πŸ“Œ Project Objective
18
+
19
+ > **Can an automated model built on satellite imagery help environmental organizations monitor illegal deforestation in near real-time?**
20
+
21
+ We aim to answer this by building a robust deep learning pipeline that:
22
+ - Collects satellite imagery for selected regions and years.
23
+ - Trains a U-Net segmentation model on forest/non-forest (or deforested) labels.
24
+ - Allows users to input coordinates + year and visualize predictions on a Leaflet map.
25
+
26
+ ---
27
+
28
+ ## πŸ›°οΈ Data Collection & Preprocessing
29
+
30
+ We use **Google Earth Engine (GEE)** to fetch Sentinel-2 or Landsat-8 imagery and NDVI indices.
31
+
32
+ ### Data Sources:
33
+ - **Imagery**: Landsat-8 (30m resolution), optionally Sentinel-2 (10m resolution).
34
+ - **Labels**: Derived using NDVI and/or forest loss layers from Global Forest Change dataset.
35
+
36
+ ### Preprocessing:
37
+ - Region-wise time-lapse collection.
38
+ - NDVI-based labeling: Thresholding NDVI to identify vegetation loss.
39
+ - Tiling large images into patches.
40
+ - Saving as `.npy` and `.tfrecord` formats for model training.
41
+
42
+ ---
43
+
44
+ ## 🧠 Model Architecture
45
+
46
+ The model uses a **U-Net architecture** implemented in **TensorFlow**, designed for image segmentation tasks.
47
+
48
+ - **Input**: Satellite image patches (RGB or NDVI composite).
49
+ - **Output**: Binary mask indicating deforested areas.
50
+
51
+ ### Features:
52
+ - Batch normalization and dropout regularization
53
+ - Dice coefficient + binary cross-entropy loss
54
+ - Data augmentation (rotation, flipping, contrast)
55
+
56
+ ---
57
+
58
+ ## βš™οΈ Training
59
+
60
+ ```bash
61
+ python train.py --epochs 50 --batch_size 16 --data_dir ./data --save_model ./models/unet_deforestation.h5
62
+
63
+ ```
64
+
65
+ ## πŸ“ˆ Evaluation
66
+
67
+ The trained model is evaluated on a held-out test set using the following metrics:
68
+
69
+ - **IoU (Intersection over Union)**: Measures the overlap between predicted deforested area and ground truth.
70
+ - **Dice Coefficient**: Especially useful for imbalanced classes.
71
+ - **Precision & Recall**: To understand false positives and false negatives.
72
+ - **F1 Score**: Harmonic mean of precision and recall.
73
+
74
+
75
+ ---
76
+
77
+ ## 🌍 Deployment
78
+
79
+ ### Hugging Face Space πŸš€
80
+ Visit: [**Deforestation Detection on Hugging Face**](https://huggingface.co/spaces/ojasrohatgi/Deforestation-Detection)
81
+
82
+ Features:
83
+ - Interactive Leaflet map to select coordinates
84
+ - Year input to analyze temporal deforestation
85
+ - On-click image fetching and prediction overlay
86
+ - Downloadable prediction masks for offline use
87
+
88
+ ### Backend Logic
89
+ The backend takes user inputs (`lat, lon, year`), queries GEE for imagery, preprocesses it into patches, passes it to the trained U-Net model, and returns a combined prediction image with overlays.
90
+
91
+ ---
92
+
93
+ ## 🧾 Project Structure
94
+
95
+ ```bash
96
+ Deforestation-Detection/
97
+ β”‚
98
+ β”œβ”€β”€ app/ # Streamlit-based frontend interface
99
+ β”‚ β”œβ”€β”€ main.py # Streamlit UI & user interaction logic
100
+ β”‚ β”œβ”€β”€ map_component.html # Leaflet map integration for coordinate input
101
+ β”‚ β”œβ”€β”€ overlay.py # Image overlay + visualization helpers
102
+ β”‚ └── utils.py # Patching, preprocessing, and GEE interaction
103
+ β”‚
104
+ β”œβ”€β”€ model/ # Trained model artifacts
105
+ β”‚ └── unet_deforestation.h5 # Final trained U-Net model
106
+ β”‚
107
+ β”œβ”€β”€ earth_engine/ # Scripts for working with GEE
108
+ β”‚ └── export_data.py # Downloads satellite images + NDVI labels
109
+ β”‚
110
+ β”œβ”€β”€ training/ # Model architecture and training logic
111
+ β”‚ β”œβ”€β”€ train.py # Model training loop
112
+ β”‚ β”œβ”€β”€ evaluate.py # Evaluation script for test data
113
+ β”‚ β”œβ”€β”€ metrics.py # IoU, Dice, and other evaluation metrics
114
+ β”‚ └── unet_model.py # Custom U-Net implementation
115
+ β”‚
116
+ β”œβ”€β”€ data/ # Data directory (images, masks, TFRecords)
117
+ β”‚ β”œβ”€β”€ train/ # Training image and mask patches
118
+ β”‚ β”œβ”€β”€ val/ # Validation image and mask patches
119
+ β”‚ └── test/ # Test image and mask patches
120
+ β”‚
121
+ β”œβ”€β”€ requirements.txt # Python dependencies
122
+ β”œβ”€β”€ README.md # This file
123
+ └── .gitattributes / .gitignore # GitHub config files
124
+ ```
125
+
126
+ ## πŸ§ͺ How to Run Locally
127
+
128
+ ### 1. Clone the repository
129
+
130
+ ```bash
131
+ git clone [https://github.com/Ojas-Rohatgi/Deforestation-Detection](https://github.com/Ojas-Rohatgi/Deforestation-Detection)
132
+ cd Deforestation-Detection
133
+
134
+ ```
135
+
136
+ ### 2. Set up a virtual environment
137
+
138
+ ```bash
139
+ python -m venv venv
140
+ source venv/bin/activate Β # On Windows: venv\Scripts\activate
141
+ pip install -r requirements.txt
142
+
143
+ ```
144
+
145
+ ### 3. Prepare data
146
+
147
+ Ensure you have satellite imagery and labeled NDVI masks stored in the `data/` folder.
148
+ You can generate training data using Earth Engine export scripts in `earth_engine/export_data.py`.
149
+
150
+ ### 4. Train the model
151
+
152
+ ```bash
153
+ python training/train.py --epochs 50 --batch\_size 16 --data\_dir ./data --save\_model ./model/unet\_deforestation.h5
154
+
155
+ ```
156
+ You can configure the number of epochs, batch size, and save path as needed.
157
+
158
+ ### 5. Run the app
159
+
160
+ ```bash
161
+ cd app
162
+ streamlit run main.py
163
+
164
+ ```
165
+ This will launch a web interface where you can:
166
+
167
+ * Select a region using the interactive Leaflet map
168
+ * Input a year (e.g., 2020)
169
+ * Fetch satellite imagery and get prediction overlays
170
+
171
+ ---
172
+
173
+ ## ☁️ Deployment
174
+
175
+ This app is live at:
176
+ πŸ”— [Hugging Face Spaces – ojasrohatgi/Deforestation-Detection](https://huggingface.co/spaces/ojasrohatgi/Deforestation-Detection)
177
+
178
+ ### Features:
179
+
180
+ * 🌍 Interactive map for selecting location
181
+ * πŸ“… Year input for time-based analysis
182
+ * πŸ“· Automatic image fetch via GEE
183
+ * 🧠 Real-time inference with trained U-Net
184
+ * πŸ–ΌοΈ Visual overlay of predictions
185
+ * ⬇️ Option to download the prediction mask
186
+
187
+ ---
188
+
189
+ ## βš™οΈ Tech Stack
190
+
191
+ | Component | Tools Used |
192
+ | ---------------- | -------------------------------------- |
193
+ | Model | TensorFlow 2.x, Keras, U-Net |
194
+ | Data Source | Google Earth Engine (Landsat-8, NDVI) |
195
+ | Frontend | Flask, Leaflet.js |
196
+ | Image Processing | NumPy, OpenCV, Matplotlib, PIL |
197
+ | Deployment | Hugging Face Spaces, GitHub |
198
+ | Output Formats | PNG masks, NumPy arrays, TFRecords |
199
+
200
+ ---
201
+
202
+ ## πŸš€ Future Roadmap
203
+
204
+ * [ ] Multi-year change detection (e.g., forest loss between 2015–2023)
205
+ * [ ] Visual heatmaps of deforestation severity
206
+ * [ ] Region-specific fine-tuning for Southeast Asia, Amazon, and Africa
207
+ * [ ] Support for multispectral and SAR imagery
208
+ * [ ] Webhooks/API integration for automated NGO alerts
209
+
210
+ ---
211
+
212
+ ## πŸ™‹β€β™‚οΈ Author
213
+
214
+ **Ojas Rohatgi**
215
+ Final Year B.Tech – Computer Science (Data Science & AI)
216
+ SRM University, Sonepat, Haryana, India
217
+
218
+ * πŸ”— GitHub: [Ojas-Rohatgi](https://github.com/Ojas-Rohatgi)
219
+ * πŸ”— Hugging Face: [ojasrohatgi](https://huggingface.co/ojasrohatgi)
220
+
221
+ ---
222
+
223
+ ## πŸ“œ License
224
+
225
+ This project is licensed under the **MIT License**.
226
+ See the [LICENSE](LICENSE) file for full license text.
227
+
228
+ ---
229
+
230
+ ## ⭐️ Support This Project
231
+
232
+ If you found this useful:
233
+
234
+ * 🌟 Star this repository on GitHub
235
+ * πŸš€ Share the Hugging Face app with your network
236
+ * πŸ“’ Report issues or suggest improvements in the Issues tab