Skip to content

Landcover classification on sentinel-2 data with Prithvi, EfficientNet-Unet and OSM / CNES Landcover labels.

License

Notifications You must be signed in to change notification settings

MaxWolf-01/sentinel2-landcover-classification

Repository files navigation

Sentinel-2 Landcover Classification (wip)

This repository contains code to train landcover classification models on Sentinel-2 data. The current pipeline allows for training a U-Net model with an EfficientNet backbone on Sentinel-2 L2A data from sentinelhub. Labels can be fetched from OpenStreetMap all over the world, or from the CNES Land Cover dataset for France. Finetuning Prithvi is WIP, as well as unsupervised pre-training for the U-Net and the Prithvi model.

The project was initially developed as part of a diploma-project at HTL-Spengergasse in cooperation with EOX IT Services and supported by the ESA Network of Resources Initiative. Team: Maximilian Wolf, Luis Kalckstein, Lilia Gerber, Dominik Fluch, Tobias Lendl

Setup

git clone git@github.com:MaxWolf-01/sentinel2-landcover-classification.git
cd sentinel2-landcover-classification
conda create -n s2lc python="3.10"
conda activate s2lc
pip install -r requirements.txt

Before you can run any scripts from the root dir, you will need to:

export PYTHONPATH="$PYTHONPATH:$(pwd)"

To download the training data, run src/data/download_sentinel.py and src/data/download_labels.py with the desired parameters. For more information, run the scripts with the --help flag or check the documentation in the source code. Configs for the data download, such as bands, resolution, timespan, evalscripts and pre-defined areas of interest can be found in src/configs/data_config.py.

Example:

python src/data/download_sentinel.py at --workers 2 --frequency QS  #  downloads a Sentinel-2 image for Austria every quarter per label
python src/data/download_labels.py at osm-multiclass --workers 4

Downloads can be interrupted and resumed by adding the --resume flag. For re-downloading, use the --overwrite flag.

Visualize the downloaded data with:

python src/data/plotting.py at osm-multiclass

Once you have the desired data, run the training script with the desired config, e.g.:

python src/train_segmentation.py at osm-multiclass efficientnet-unet-b5 --bs 32 --epochs 30 --loss-type focal --weighted-loss --name "wandb-run-name"  # disable wandb with "--wandb"

Flags like --type debug set presets for a batch size of 1, no logger, compiling, etc.

To use Prithvi, download the pretrained weights of the Prithvi foundation model from Hugging Face:

curl -L "https://huggingface.co/ibm-nasa-geospatial/Prithvi-100M/resolve/main/Prithvi_100M.pt?download=true" -o "weights/Prithvi_100M.pt"

Contributer Infos

Before commiting, make sure to

pip install pre-commit
pre-commit install

Or run pre-commit run --all-files to check manually.

To log runs to the wandb team workspace, add the name of the wandb entity in the .env file as WANDB_ENTITY.

Acknowledgements