Skip to main content

EarthNet Models PyTorch

Project description

earthnet-models-pytorch

A PyTorch lightning library for Earth surface forecasting.

This library contains models, dataloaders and scripts for Earth surface forecasting in the context of research surrounding the EarthNet challenge.

It is currently under development, thus do expect bugs and please report them!

The library is build on PyTorch, a Python deep learning library, and PyTorch Lightning, a PyTorch wrapper reducing boilerplate code and adding functionality to scale experiments.

In earthnet-models-pytorch there is three main components:

1. Model - plain PyTorch models just implementing simple forward passes.
2. Setting - Dataset and Metrics for a particular problem
3. Task - Abstraction for the training, validation & test loops, tying together models and settings, normally both models and settings are task-specific.

Requirements

We recommend using Anaconda for managing dependencies of this library. The following bash commands create a suitable environment. Please note the PyTorch installation requirements for your system, see (https://pytorch.org/) - esp. cudatoolkit might have to be installed with a different cuda version.

conda create -n emp -c conda-forge python 
conda activate emp
pip install torch torchvision --index-url https://download.pytorch.org/whl/cu126
pip install numpy matplotlib pillow xarray zarr netcdf4 scipy imageio networkx scikit-image s3fs pyproj pyarrow seaborn cartopy tensorboard dask pytorch-lightning torchmetrics statsmodels earthnet earthnet-minicuber segmentation-models-pytorch albumentations ipykernel

Installation

pip install git+https://github.com/vitusbenson/earthnet-models-pytorch.git

or:

git clone https://github.com/vitusbenson/earthnet-models-pytorch.git
cd earthnet-models-pytorch
pip install -e .

or:

pip install earthnet-models-pytorch

Note, the latter is only recommended if all you plan to do is use existing code from earthnet-models-pytorch. For developing, the best is to clone the repository locally and install as editable with pip install -e.

Debug

The design process of a new model or feature is supported in earthnet-models-pytorch by a debug option. Since models often require both a lot of data and GPUs to test the complete training cycle, we use this debug option rather than classic unit testing. In order to use it, we need to set up a config.yaml containing all configs for the different components. See the configs folder for examples. It is recommended to save the setting in a folder structure configs/<setting>/<model>/<feature>/base.yaml. If done in this way, the earthnet-models-pytorch logger automatically detects the correct naming for later.

We can check if a model works as desired by running:

debug.py path/to/setting.yaml

It starts with a fast dev run in PyTorch lightning, which is essentially just performing two train, validation and test loops. It then also overfits a model on 4 batches for 1000 epochs, to check if gradients flow properly and the model does indeed learn.

Note, the debug and all other scripts are registered by PyPI, so it does not matter from which directory they are started and we dont need to use python for them, they should always work.

Train

In order to train a model we again need to set up a config.yaml, see above regarding for more details.

Then we just do:

train.py path/to/setting.yaml

It trains the model as specified in the config.

Tune

Hyperparameter tuning. Explanation tbd.

Test

The script for testing a trained model works as follows:

test.py path/to/setting.yaml path/to/checkpoint track --pred_dir path/to/predictions/directory/

Here we replace track by the track that we want to test on; this depends on the particular setting you choose. For example in en21-std there are 4 tracks: iid, ood, ex and sea.

Plot

Plotting functionality. Explanation tbd.

API

earthnet_models_pytorch.task

The task is a PyTorch Lightning module that implements the training, validation and testing loops as well as the optimization and logging necessary. Tasks include:

  • spatio-temporal
  • pixelwise test-time gradients and statistical models

spatio-temporal

The required data has

  • dynamic
  • dynamic_mask
  • static
  • static_mask
  • filepath
  • cubename
  • (landcover)

The model forward takes a batch dict, pred_start as the first index to be predicted of the first tensor in the dynamic list and n_preds as the prediction length.

A setting must implement a metric with a Lightning metrics interface. Note: The Lightning metrics interface as used in this library right now is currently beeing deprecated, thus we will also rework this part.

earthnet_models_pytorch.setting

The setting is a combination of a Lightning DataModule and a Lightning Metric. Settings include:

  • en21-std; the setting of the EarthNet2021 challenge.
  • en21-veg; Only predicting vegetation on EarthNet2021 data with additional S2GLC Landcover data.
  • en21x; The EarthNet2021x data, which is reworked data from the EarthNet2021 challenge, now focusing on vegetation forecasting in Europe.
  • en21x-px; Same as en21x, but using pixelwise data from a .csv to efficiently create batches for pixelwise models.
  • en22; The EarthNet2022 data from the DeepCube UC1 project. Similar to en21x.

Important is that the respective lists and dicts in the init are filled and that possible global arguments are mapped in the parse.py.

earthnet_models_pytorch.model

The model is a PyTorch nn.Module with build-in parser for hyperparameters (much like a Lightning Module). The forward must align with the requirements of the appropriate task.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

earthnet_models_pytorch-0.1.1.tar.gz (68.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

earthnet_models_pytorch-0.1.1-py3-none-any.whl (90.2 kB view details)

Uploaded Python 3

File details

Details for the file earthnet_models_pytorch-0.1.1.tar.gz.

File metadata

  • Download URL: earthnet_models_pytorch-0.1.1.tar.gz
  • Upload date:
  • Size: 68.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for earthnet_models_pytorch-0.1.1.tar.gz
Algorithm Hash digest
SHA256 d07e295efc33620bd56b85e5464d5622ab8a1ac6af29d9251829d046e1f031a2
MD5 83d463de27603849b66e8b36b28d47f3
BLAKE2b-256 43baa1e26fb9c33ccd27adddfba7349c2401ab0b459060f280ad7c0cdfe21021

See more details on using hashes here.

File details

Details for the file earthnet_models_pytorch-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for earthnet_models_pytorch-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 deeab11549110eb53daaf24f3a97ab8379bb768357ca9b9e91bc3b5bf8796ad7
MD5 6f9c7733f285637c63cc4d23fbcd327a
BLAKE2b-256 036fa72e20c8ce8e48cdee11617cd7f74fb6c02e27d51767205142d03896246c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page