An end-to-end deep learning pipeline using a U-Net (ResNet-34) architecture to automatically detect and segment traditional and modern olive groves from 14-band Sentinel-2 satellite imagery in Tunisia.
# Tunisia Olive Tree Detection 🫒🛰️
This repository contains an end-to-end deep learning pipeline for automatically detecting and segmenting olive groves from Sentinel-2 satellite imagery in Tunisia.
The model distinguishes between two different types of olive agriculture:
1. **Extensif (Traditional):** Widely spaced olive trees typical of central/southern Tunisia.
2. **Intensif (Modern):** High-density, closely planted olive orchards.
3. **Background:** Non-olive areas including cities, mountains, desert, and bare soil.
## Project Structure
### 1. Data Collection (Google Earth Engine)
We use Sentinel-2 imagery (10m/20m resolution) collected during the summer (June–August) to maximize the contrast between evergreen olive trees and dry summer soil.
- **`gee_sentinel2_olive_tunisia.js`**: Core script to export large mosaic regions from GEE with 14 bands (10 raw bands + 4 indices: NDVI, NDWI, EVI, SAVI).
- **`gee_auto_training_data.js`**: Script to generate and export massive amounts of training polygons automatically.
- **`gee_export_test.js`**: Quick script to export a small test region of 10-band Sentinel-2 data for running through the web app.
### 2. Training Pipeline (PyTorch)
The core model is a **U-Net** architecture with a **ResNet-34** encoder (often referred to as a U-Net ResNet-34), powered by `segmentation_models_pytorch`. It was trained on over 5,300 custom image chips (128x128 pixels, 14 channels) to ensure robust generalisation across deserts, cities, and agricultural zones.
- **`train_unet_olive.py`**: The main script for training the U-Net model and calculating dataset statistics.
- **`chip_training_v2.py`**: Script to slice large Sentinel-2 TIFFs and vector polygons into `128x128` training chips and masks.
- **`chip_backgrounds.py`**: Script to add negative samples (e.g. cities, deserts) to the dataset with zero-masks to reduce false positives.
- **`band_stats.json`**: Pre-calculated normalisation statistics (mean/std) for the 14 Sentinel-2 band …