This repository contains the code to reproduce the results in the paper "Effect of the output activation function on the probabilities and errors in medical image segmentation".
The tests in the paper were run on a Google Cloud server. Training all neural networks takes about 2 weeks on a single Tesla K80.
- (Optional) Run
./google_cloud.sh
to create the server. - Install
segmentation-models-pytorch==0.2.0
,albumentations==1.0.1
,nibabel==3.2.1
,scikit-image==0.18.2
andpytorch 1.9.0
. - Download one or more datasets (see below).
- (Optional) Run
./train_all.sh
.
Each dataset folder has one or more preprocessingX.py
scripts. The preprocessing scripts create a folder "processed_training" with subdirectories 0, 1, ..., n containing the files processed_0.npy, processed_1.npy, ..., processed_n.npy (and some debug files). It is easy to add new segmentation datasets by using the same data structure and adding similar preprocessing scripts.
- Register and download the dataset from https://acdc.creatis.insa-lyon.fr/
- Unzip the dataset inside the folder "ACDC" (input files: ACDC/training/patientXXX/*).
- Run
python preprocess1.py
- Run
python preprocess2.py
- Run
python3 train.py "sigmoid_activation" "Unet" "BCELoss" "ACDC/processed_training"
- Register and download the dataset from https://www.smir.ch/ISLES/Start2018
- Unzip the dataset inside the folder "ISLES" (input files: ISLES/TRAINING/case_X/*).
- Run
python preprocess1.py
- Run
python3 train.py "sigmoid_activation" "Unet" "BCELoss" "ISLES/processed_training"
- Download the dataset from https://datasets.simula.no/kvasir-seg/#download
- Unzip the dataset inside the folder "Kvasir" (input files: Kvasir-SEG/images/* and Kvasir-SEG/masks/*).
- Run
python preprocess1.py
- Run
python3 train.py "sigmoid_activation" "Unet" "BCELoss" "Kvasir/processed_training"
- Download the dataset from http://medicaldecathlon.com/ (only Task05_Prostate.tar)
- Unzip the dataset inside the folder "MSD" (input files: Task05_Prostate/imagesTr/* and Task05_Prostate/labelsTr/*)
- Run
python preprocess1.py
- Run
python3 train.py "sigmoid_activation" "Unet" "BCELoss" "MSD/processed_training"
The script train.py
saves the log and model files in individual folders e.g. MSD-DiceLoss-arctan_activation-resnet34-Unet. Each folder contains csv files "fold-k/fold-k-log.csv" (for all folds k). The script generate_table.py
creates from these results a LaTeX table.
The default settings in train.py
are deterministic (if the script is run on the same machine). However, changing the decoder can lead to non-deterministic results (even if you set the random seed). The reason is that segmentation_models.pytorch uses different interpolation settings depending on the architecture. U-Net with F.interpolate
and nearest neighbor interpolation is deterministic, but bilinear interpolation as found in FPN is not necessarily deterministic. This must therefore be taken into account when choosing a decoder and using a GPU.
@misc{nieradzik2021effect,
title={Effect of the output activation function on the probabilities and errors in medical image segmentation},
author={Lars Nieradzik and Gerik Scheuermann and Dorothee Saur and Christina Gillmann},
year={2021},
eprint={2109.00903},
archivePrefix={arXiv},
primaryClass={cs.CV}
}