Home

Awesome

Sen4AgriNet Models

Contributors: Sykas D., Zografakis D., Sdraka M.

This repository contains the models and training scripts for reproducing the experiments presented in:
A Sentinel-2 multi-year, multi-country benchmark dataset for crop classification and segmentation with deep learning.

Description

Based on the Sen4AgriNet dataset, we produce two distinct sub-datasets of Sentinel-2 L1C images for experimentation:

The above sub-datasets were downsized in order to be used for the experiments in this repository. Specifically, 5000 patches with 60-20-20 (train-val-test) split were sampled from each sub-dataset and the 11 most frequent classes were kept (wheat, maize, sorghum, barley, rye, oats, grapes, rapeseed, sunflower, potatoes, peas). Three different scenarios were explored:

ScenarioTrainTest
1Catalonia (2019, 2020), France (2019)Catalonia (2019, 2020), France (2019)
2Catalonia (2019, 2020)France (2019)
3France (2019)Catalonia (2020)

The input of the PAD models is the median of each month of observations from April through September. The OAD models take as input the aggregated statistics of these observations.

For a full reproduction of the experiments presented in the associated publication, please download the netCDF files from one of the following sources: Dropbox, Google Drive or HuggingFace Hub (experimental). In this Dropbox folder you can also find the COCO files and the weights of the trained models.

Requirements

This repository was tested on:

Check requirements.txt for other essential modules.

Available models

For PAD:

  1. ConvLSTM
  2. ConvSTAR
  3. U-Net
  4. TempCNN

For OAD:

  1. TempCNN
  2. LSTM
  3. Transformer

Instructions

Folder structure

S4A-models\
    L dataset\
        L netcdf\
        L oad\
    L coco_files\
    L logs\
        L medians
    L model\
    L utils\
        L settings\
            L mappings\

COCO files

In the coco_files/ folder are the COCO files required for training, validating and testing the models.

NetCDF4 files

In the dataset/netcdf/ folder you should place the downloaded netCDF4 files.

OAD files

In the dataset/oad/ folder you should place the exported files containing the OAD statistics.

Configuration

Every script inherits settings from the aforementioned files.

Essential scripts

Using the repo

Preparation

  1. (Optional) Run export_medians_multi.py to precompute the medians needed for training, validation and testing.
  2. If you don't want to use the given COCO files, then export your own using the coco_data_split.py script.
  3. Uncomment the precomputed class weights in the corresponding section of the configuration file depending on the scenario you are using (or compute your own).
  4. Especially for OAD, run object-based-csv.py to export the statistics needed for the experiments.

For PAD:

  1. Run pad_experiments.py with the appropriate arguments. Example:
    python pad_experiments.py --train --model convlstm --parcel_loss --weighted_loss --root_path_coco <coco_folder_path> --prefix_coco <coco_file_prefix> --netcdf_path <netcdf_folder_path> --prefix <run_prefix> --num_epochs 10 --batch_size 32 --bands B02 B03 B04 B08 --saved_medians --img_size 61 61 --requires_norm --num_workers 16 --num_gpus 1 --fixed_window
    
    The above command is for training the ConvLSTM model using the weighted parcel loss described in the associated publication. Training will continue for 10 epochs with batch size 32, using the Sentinel-2 bands Blue (B02), Green (B03), Red (B04) and NIR (B08). The input image size is 61x61, the precomputed medians are used to speed up training and all input data are normalized. Finally, a fixed window is used containing months 4 (April) through 9 (September). Please use the --help argument to find information on all available parameters.
  2. Optionally, after training run visualize_predictions.py to visualize the image, ground truth and prediction for a specific model and image.

For OAD:

  1. Run oad_experiments.py with the appropriate arguments. Example:
    python oad_experiments.py --train --model transformer --prefix <run_prefix> --file <oad_file_name> --num_epochs 10 --batch_size 32 --num_workers 16 --num_gpus 1 --hidden_size 1024 --num_layers 3
    
    The above command is for training the Transformer model. Training will continue for 10 epochs with batch size 32, using given file containing the OAD statistics. The hidden size is 1024 and three layers are used for the model. Please use the --help argument to find information on all available parameters.

Reported results

The results reported on the given COCO files are presented in the following tables.

PAD

ScenarioModelAcc. W. (%)F1 W. (%)Precision W. (%)
1U-Net93.7082.6186.64
1ConvLSTM94.7285.1886.86
1ConvSTAR92.7880.3883.33
2U-Net83.1257.8561.57
2ConvLSTM82.5356.5660.57
2ConvSTAR79.5252.1558.98
3U-Net72.1143.5468.42
3ConvLSTM69.8640.4766.17
3ConvSTAR69.0734.4567.43

OAD

ScenarioModelAcc. W. (%)F1 W. (%)Precision W. (%)
1LSTM88.5288.0387.85
1Transformer88.3688.1087.90
1TempCNN90.0889.9790.01
2LSTM91.5591.3491.31
2Transformer39.1731.4558.52
2TempCNN36.9030.1460.71
3LSTM60.6063.9670.55
3Transformer51.2156.7167.76
3TempCNN52.3257.3868.35

Citation

If you use our work, please cite:

@ARTICLE{
  9749916,
  author={Sykas, Dimitrios and Sdraka, Maria and Zografakis, Dimitrios and Papoutsis, Ioannis},
  journal={IEEE Journal of Selected Topics in Applied Earth Observations and Remote Sensing},
  title={A Sentinel-2 multi-year, multi-country benchmark dataset for crop classification and segmentation with deep learning},
  year={2022},
  doi={10.1109/JSTARS.2022.3164771}
}