Public pytorch implementation for our paper Shortcut Learning in Medical Image Segmentation. This code repository contains Case B part of the paper, where we investigated the shortcut learning in skin lesion segmentation caused by zero-padded convolutions and center cropped training sets.
If you find this code helpful in your research, please cite the following paper:
@article{lin2024shortcut,
title={Shortcut Learning in Medical Image Segmentation},
author={Lin, Manxi and Weng, Nina and Mikolaj, Kamil and Bashir, Zahra and Svendsen, Morten Bo S{\o}ndergaard and Tolsgaard, Martin and Christensen, Anders Nymark and Feragen, Aasa},
journal={arXiv preprint arXiv:2403.06748},
year={2024}
}
This paper is accepted at MICCAI 2024, Morocco (the 27th International Conference on Medical Image Computing and Computer Assisted Intervention).
The code is implemented in Python 3.9 using the Pytorch library. We only tested the code with Pytorch 3.9. One way of getting all the requirements is by using virtualenv and the requirements.txt file.
pip install -r requirements.txt
import sys
if PATH_OF_YOUR_REPO not in sys.path:
sys.path.append(PATH_OF_YOUR_REPO)
REPO_PATH = PATH_OF_YOUR_REPO
DATASET_PATH = PATH_OF_DATASET
Datsets used in this work: Here
Run python3 ./prepare_data/main.py
. The csv files that will be used later, will be saved under ./datafiles/
.
Training:
Run python3 ./train/train_seg.py
Change the config variable isCrop
in train_config.py
for trainning with cropped images.
Inference:
Run python3 ./train/inference_seg.py
.
Change the configuration in inference_config.py
.
Run python3 ./analysis/metrics_by_rings.py
.
Results are saved at ./records/analysis/metrics_by_rings/
.
Change version_num
to the one you want to test on.
Run python3 ./analysis/moving_patch.py
.
Results are saved at ./records/analysis/moving_patch/
.
Change version_num
to the one you want to test on.
/analysis/
contains codes for analysis the effect of shortcut learning./datafiles/
contains csv files used for training./figures/
contains figures used for README file./models/
contains codes for segmentation models./prepare_data/
contains codes for creating csv files./records/
contains running results./train/
contains codes for training and inference.
The datasets used in this work are all public and can be downloaded from:
Please use the issue tracking tool to report bugs or email directly to ninwe@dtu.dk. If you have further questions regarding the paper, please feel free to email ninwe@dtu.dk as well.