Skip to content

Code for training and evaluating wetland segmentation models, used in a pre-study about AI for wetland monitoring in Sweden

Notifications You must be signed in to change notification settings

aleksispi/ai-swetlands

Repository files navigation

AI-Swetlands: A pre-study about using artificial intelligence for semantic segmentation of Swedish wetland types

This repo contains Python- and PyTorch-based code for training and evaluating wetland segmentation models, that was used in a pre-study about AI for wetland monitoring in Sweden during the fall of 2022. A popular scientific description in Swedish can be hound here.

Funding and acknowledgements

This study was conducted by Aleksis Pirinen, RISE Research Institutes of Sweden, for the Swedish Environmental Protection Agency (contact person and collaboration partner: Matti Ermold) during September - November, 2022. The Swedish Environmental Protection Agency funded this work. We would like to thank William Lidberg at the Swedish University of Agricultural Sciences for all the help with transforming model predictions to a format that works when visualizing in GIS.

Data preprocessing

Note: Before starting with this data preprocessing step, ensure you have access to the various tiff-files referenced in preprocess_wetlands.py.

The first file to consider is preprocess_wetlands.py, which will preprocess the input and output maps and save them as non-overlapping rectangles of a size that can be specified in preprocess_wetlands.py (100 x 100 patches were used in the pre-study). After this, use the file save_and_align_data.py to complete the preprocessing and data alignment.

Training a model for wetland segmentation

Note: Ensure you have completed the data preprocessing step above prior to this.

Model training (and validation on validation data) is performed using wetland_training.py. See the file plot_results.py if you are interested in tracking the progress of mIoU and other training statistics. Models are saved during and upon completion of training, and can subsequently be used for example to map Swedish wetlands across all of Sweden (see below).

Using a pre-trained segmentation model across all of Sweden to perform a full wetland mapping

Note: Ensure you have trained a segmentation model (see above) prior to this.

The file segment_all_of_sweden.py contains the code needed to evaluate a pre-trained segmentation model at every location of Sweden. This can be very memory-demanding for the computer, so there is an option to run this code in "chunks" that splits Sweden into N subsets, by using the shell script launch_loop.sh.

Once you have evaluated the segmentation network in all locations, the results can be merged into a unified "wetland map" spanning all of Sweden, by using the script merge_tiffs.py. Finally, if you are interested in exporting the results to GIS, consider the file write_geotiff.py.

About

Code for training and evaluating wetland segmentation models, used in a pre-study about AI for wetland monitoring in Sweden

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published