Pretraining coastline image segmentation models. The automated annotation method, used to pretrian models, is based on superpixels and spectral indices.
This repository contains the code required to reproduce the results in the conference paper:
Coming soon
This code is only for academic and research purposes. Please cite the above paper if you intend to use whole/part of the code.
We have used the following dataset in our analysis:
- The Landsat Irish Coastal Segmentation (LICS) Dataset found here.
The data is available under the Creative Commons Attribution 4.0 International license.
You can find the following files in the src folder:
1_format_data.ipynb
: This file formats the fine-tune annotations and combines them with the appropriate satellite image bands. It works in conjunction with 1_label_studio.ipynb to prepare the dataset for model training.1_label_studio.ipynb
: Helps create precise fine-tune annotations using Label Studio.2_explore_superpixels.ipynb
: Explores superpixel algorithms and parameters (e.g., spectral bands, indices, threshold methods). This file experiments with different configurations to optimize the superpixel segmentation process.3_finetune_models.ipynb
: This script fine-tunes models previously trained on superpixel data.4_evaluate_models_lics.ipynb
: Evaluates different segmentation models, including a deterministic superpixel algorithm and U-Net variants, on the LICS test dataset. Key metrics such as accuracy, precision, recall, and F1 score are computed.4_evaluate_models_swed.ipynb
: Similar to 4_evaluate_models_lics.ipynb, this file evaluates segmentation models on the SWED test dataset and calculates various performance metrics.format_swed.py
: Processes the SWED dataset by combining image and label files into single files with an additional label channel. This script prepares the SWED dataset for model training or testing.apply_superpixels.py
: This script applies superpixel algorithms to image files in the input directory and saves the results in the output directory. It processes .npy image files to generate superpixel segmentation.dataset_test.py
: This file tests the dataset generated by the apply_superpixels.py script. It counts .npy files in a directory and checks that all files have the expected shape.network.py
: Defines the deep learning models used in the project, such as U-Net and its variants. It also contains a function to initialize the weights of the models.train.py
: This script handles the training of U-Net models for coastline detection. It includes argument parsing for dataset specifications and calls the model training pipeline using various model architectures.evaluation.py
: Contains evaluation methods for assessing models. It includes functions like shuffling and permutating image spectral bands for model testing and evaluating the performance of segmentation algorithms.utils.py
: Contains utility functions used throughout the project. These include functions for handling image data, applying segmentation methods like SLIC and Felzenszwalb, and performing image processing tasks.
Use the following commands to format datasets, create training masks and train models.
SWED is different from LICS, so we need to format it:
python format_swed.py --input_dir <path_to_swed_dataset>
To apply superpixel segmentation to the datasets:
For Landsat data:
python apply_superpixels.py --input_dir <path_to_landsat_dataset> --satellite landsat
For Sentinel data:
python apply_superpixels.py --input_dir <path_to_sentinel_dataset> --satellite sentinel
To ensure the datasets are correctly formatted:
For Landsat data:
python dataset_test.py <path_to_landsat_dataset> landsat
For Sentinel data:
python dataset_test.py <path_to_sentinel_dataset> sentinel
Example for running code:
python train.py --model_name TEST --satellite landsat --incl_bands [1,2,3,4,5,6,7] --early_stopping 10 --train_path <path_to_landsat_dataset> --target_pos 8 --save_path output/models/ --note "Model test"
This command will train the model using the specified dataset, model name, satellite type (landsat/sentinel), and other parameters such as early stopping and device.