Awesome
[NeurIPS-2023] Towards Generic Semi-Supervised Framework for Volumetric Medical Image Segmentation
This repo is the official implementation of Towards Generic Semi-Supervised Framework for Volumetric Medical Image Segmentation which is accepted at NeurIPS-2023.
π The significance of this work lies in its ability to encourage semi-supervised medical image segmentation methods to address more complex real-world application scenarios, rather than just developing frameworks in ideal experimental environments. Furthermore, we have consolidated all four settings within this single codebase, enabling the execution of any task using a single bash file by merely adjusting the arguments.
<p align = "center"> <img src="./images/analysis.png" width="70%"/> </p> <p align = "center"> <img src="./images/Framework.png" width="80%"/> </p>Online Presentation Video is available for brief introduction.
1. Environment
First, create a new environment and install the requirements:
conda create -n genericssl python=3.8
conda activate genericssl
cd GenericSSL/
pip install -r requirements.txt
[πIMPORTANT] Then, before running the code, set the PYTHONPATH
to pwd
:
export PYTHONPATH=$(pwd)/code:$PYTHONPATH
2. Data Preparation
First, download the datasets and put them under the Datasets
folder:
-
LASeg dataset for SSL: download the preprocessed data from https://github.com/yulequan/UA-MT/tree/master/data.
-
Synapse dataset for IBSSL: The MR imaging scans are available at https://www.synapse.org/#!Synapse:syn3193805/wiki/. Please sign up and download the dataset. πππ Or download the preprocessed data via this link.
-
MMWHS dataset for UDA: download according to https://github.com/cchen-cc/SIFA#readme. πππ Or download the preprocessed data via this link.
-
M&Ms dataset for SemiDG: download from https://www.ub.edu/mnms/, after unzipping the dataset, you will get an
OpenDataset
folder, then you need to run thepython coda/data/split_MNMS_data.py
to spilt and getMNMs
folder. πππ Or download the preprocessed data via this link.
The file structure should be:
.
βββ Datasets
βΒ Β βββ LASeg
βΒ Β βΒ Β βββ 2018LA_Seg_Training Set
βΒ Β βΒ Β βΒ Β βββ 0RZDK210BSMWAA6467LU
βΒ Β βΒ Β βΒ Β βΒ Β βββ mri_norm2.h5
βΒ Β βΒ Β βΒ Β βββ 1D7CUD1955YZPGK8XHJX
βΒ Β βΒ Β βΒ Β βββ ...
βΒ Β βΒ Β βββ test.list
βΒ Β βΒ Β βββ train.list
βΒ Β βββ MMWHS
βΒ Β βΒ Β βββ CT
βΒ Β βΒ Β βΒ Β βββ imagesTr
βΒ Β βΒ Β βΒ Β βΒ Β βββ ct_train_1001_image.nii.gz
βΒ Β βΒ Β βΒ Β βΒ Β βββ ...
βΒ Β βΒ Β βΒ Β βββ labelsTr
βΒ Β βΒ Β βΒ Β βΒ Β βββ ct_train_1001_label.nii.gz
βΒ Β βΒ Β βΒ Β βΒ Β βββ ...
βΒ Β βΒ Β βββ MR
βΒ Β βΒ Β βββ imagesTr
βΒ Β βΒ Β βββ labelsTr
βΒ Β βββ MNMs
βΒ Β βΒ Β βββ Labeled
βΒ Β βΒ Β βββ VendorA
βΒ Β βΒ Β Β Β βΒ Β βββ A0S9V9
βΒ Β βΒ Β Β Β βΒ Β βΒ Β βββ A0S9V9_sa.nii.gz
βΒ Β βΒ Β Β Β βΒ Β βΒ Β βββ A0S9V9_sa_gt.nii.gz
βΒ Β βΒ Β Β Β βΒ Β βββ A1D9Z7
βΒ Β βΒ Β Β Β βΒ Β βββ ...
βΒ Β βΒ Β βββ VendorB
βΒ Β βΒ Β βββ VendorC
βΒ Β βΒ Β βββ VendorD
βΒ Β βββ OpenDataset
βΒ Β βΒ Β βββ Testing
βΒ Β βΒ Β βββ Training
βΒ Β βΒ Β βββ Validation
βΒ Β βΒ Β βββ mnms_dataset_info.xls
βΒ Β βββ Synapse
βΒ Β βββ imagesTr
βΒ Β Β Β βΒ Β βββimg0001.nii.gz
βΒ Β Β Β βΒ Β βββ ...
βΒ Β βββ labelsTr
βΒ Β Β Β Β Β βββlabel0001.nii.gz
βΒ Β Β Β Β Β βββ ...
2.1 Pre-process LASeg dataset
Run python ./code/data/preprocess_la.py
to:
- convert
.h5
files to.npy
. - generate the labeled/unlabeled splits
2.2 Pre-process Synapse dataset
Run python ./code/data/preprocess_synapse.py
to
- resize the images and convert to
.npy
for faster loading; - generate the train/test splits (use labeled data for validation);
- generate the labeled/unlabeled splits.
2.3 Pre-process MMWHS dataset
Run python ./code/data/preprocess_mmwhs.py
to:
- reorient to the same orientation, RAI;
- convert to continuous labels;
- crop centering at the heart region;
- for each 3D cropped image top 2/% of its intensity histogram was cut off for alleviating artifacts;
- resize and convert to
.npy
; - generate the train/validation/test splits.
2.4 Pre-process M&Ms dataset
Run python ./code/data/preprocess_mnms.py
to:
- split the original 4D data to 3D along the time axis;
- crop and resize;
- save to
.npy
; - generate the train/test splits (use labeled data for validation);
- generate the labeled/unlabeled splits.
For all the pre-processing, you can comment out the functions corresponding to splits and use our pre-split files.
Finally, you will get a file structure as follow:
.
βββ Synapse_data
β βββ npy
β β βββ <id>_image.npy
β β βββ <id>_label.npy
β β βββ ...
β βββ split_txts
β βββ labeled_0.2.txt
β βββ unlabeled_0.2.txt
β βββ train.txt
β βββ eval.txt
β βββ test.txt
β βββ ...
βββ LA_data
β βββ ...
βββ MMWHS_data
β βββ ...
βββ MNMS_data
βββ ...
3. Training & Testing & Evaluating
π₯π₯ This codebase allows train, test, and evaluate on all the four settings using one single bash file. π₯π₯
Run the following commands for training, testing and evaluating.
bash train.sh -c 0 -e diffusion -t <task> -i '' -l 1e-2 -w 10 -n 300 -d true
Parameters:
-c
: use which gpu to train
-e
: use which training script, can be diffusion
for train_diffusion.py
, or diffusion_2d
for train_diffusion_2d.py
-t
: switch to different tasks:
Β Β Β Β Β For SSL on 5%
labeled LA dataset: la_0.05
Β Β Β Β Β For IBSSL on 20%
labeled Synapse dataset: synapse_0.2
Β Β Β Β Β For UDA on MMWHS dataset: mmwhs_ct2mr
for labeled CT and unlabeled MR, mmwhs_mr2ct
in opposite
Β Β Β Β Β For SemiDG on M&Ms dataset, 2%
labeled B,C,D -> A
setting: mnms_A_0.02
; 5%
labeled A,B,C -> D
setting: mnms_D_0.05
-i
: name of current experiment, can be whatever you like
-l
: learning rate
-w
: weight of unsupervised loss
-n
: max epochs
-d
: whether to train, if true
, training -> testing -> evaluating; if false
, testing -> evaluating
4. Results & Model Weights
ππ All trained model weights can be downloaded from this link. ππ
Put the logs
directory under the root directory of this repo and set -d False
, then you can test and evaluate the models.
4.1 Imbalance SSL on Synapse dataset
4.2 SSL on LASeg dataset & UDA on MMWHS dataset
4.3 SemiDG on M&Ms dataset
Citations
If this code is helpful for your study, please cite:
@inproceedings{wang2023towards,
title={Towards Generic Semi-Supervised Framework for Volumetric Medical Image Segmentation},
author={Wang, Haonan and Li, Xiaomeng},
booktitle={Thirty-seventh Conference on Neural Information Processing Systems},
year={2023}
}
Contact
Haonan Wang (hwanggr@connect.ust.hk)
License
This repository is released under MIT License.