diff --git a/README.md b/README.md index d08768e..6ae6718 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # Overview -This repository provides source code and pre-trained models for brain tumor segmentation with BraTS dataset. The method is detailed in [1], and it won the 2nd place of MICCAI 2017 BraTS Challenge. +This repository provides source code and pre-trained models for brain tumor segmentation with BraTS dataset. The method is detailed in [1], and it won the 2nd place of MICCAI 2017 BraTS Challenge. In addition, it is adapted to deal with BraTS 2015 dataset. This implementation is based on NiftyNet and Tensorflow. While NiftyNet provides more automatic pipelines for dataloading, training, testing and evaluation, this naive implementation only makes use of NiftyNet for network definition, so that it is lightweight and extensible. A demo that makes more use of NiftyNet for brain tumor segmentation is proivde at https://cmiclab.cs.ucl.ac.uk/CMIC/NiftyNet/tree/dev/demos/BRATS17 @@ -26,60 +26,60 @@ An example of brain tumor segmentation result. pip install niftynet ``` -* BraTS dataset. Data can be downloaded from http://braintumorsegmentation.org/ +* BraTS 2015 or 2017 dataset. Data can be downloaded from http://braintumorsegmentation.org/ # How to use ## 1, Prepare data -* Download BraTS dataset, and uncompress the file to `./data` folder. For example, the training set will be in `./data/Brats17TrainingData` and the validation set will be in `./data/Brats17ValidationData`. +* Download BraTS dataset, and uncompress the training and tesing zip files. For example, the training set will be in `data_root/BRATS2015_Training` or `data_root/Brats17TrainingData` and the validation set will be in `data_root/BRATS2015_Validation`. -* Process the data. Run: - -```bash -python pre_process.py -``` - -## 2, Use pre-trained models -* Download pre-trained models from https://drive.google.com/open?id=1moxSHiX1oaUW66h-Sd1iwaTuxfI-YlBA, and save these files in `./model_pretrain`. -* Obtain binary segmentation of whole tumors, run: +## 2, Use pre-trained models to segment images +* To segment BraTS 2015 data, run: ```bash -python test.py config/test_wt.txt +python test.py config15/test_all_class.txt ``` -* Obtain segmentation of all the tumor subregions, run: +* To segment BraTS 2017 data, run: ```bash -python test.py config/test_all_class.txt +python test.py config17/test_all_class.txt ``` + ## 3, How to train The trainig process needs 9 steps, with axial view, sagittal view, coronal view for whole tumor, tumor core, and enhancing core, respectively. -The following commands are examples for these steps. However, you can edit the corresponding `*.txt` files for different configurations. +The following commands are examples for BraTS 2017. However, you can edit the corresponding `*.txt` files for different configurations. * Train models for whole tumor in axial, sagittal and coronal views respectively. Run: ```bash -python train.py config/train_wt_ax.txt -python train.py config/train_wt_sg.txt -python train.py config/train_wt_cr.txt +python train.py config17/train_wt_ax.txt +python train.py config17/train_wt_sg.txt +python train.py config17/train_wt_cr.txt ``` * Train models for tumor core in axial, sagittal and coronal views respectively. Run: ```bash -python train.py config/train_tc_ax.txt -python train.py config/train_tc_sg.txt -python train.py config/train_tc_cr.txt +python train.py config17/train_tc_ax.txt +python train.py config17/train_tc_sg.txt +python train.py config17/train_tc_cr.txt ``` * Train models for enhancing core in axial, sagittal and coronal views respectively. Run: ```bash -python train.py config/train_en_ax.txt -python train.py config/train_en_sg.txt -python train.py config/train_en_cr.txt +python train.py config17/train_en_ax.txt +python train.py config17/train_en_sg.txt +python train.py config17/train_en_cr.txt +``` + +* To save the time for training, you may use the modals in axial view as initalizations for sagittal and coronal views. Copy variales in axial view to those in sagittal or coronal view by running: +```bash +python util/rename_variables.py ``` +You may need to edit this file to set different parameters. As an example for Brats 2015, after running this command, you will see a model named `model15/msnet_tc32sg_init` that is copied from `model15/msnet_tc32_20000.ckpt`. Then just set `start_iteration=1` and `model_pre_trained=model15/msnet_tc32sg_init` in `config15/train_tc_sg.txt`. ## 4, How to test -Similar to 'Use pre-trained models', write a configure file that is similar to `config/test_wt.txt` or `config/test_wt.txt` and +Similar to 'Use pre-trained models', write a configure file that is similar to `config15/test_all_class.txt` or `config17/test_all_class.txt` and set the value of model_file to your own model files. Run: ```bash python test.py your_own_config_for_test.txt @@ -88,6 +88,6 @@ python test.py your_own_config_for_test.txt ## 5, Evaluation Calcuate dice scores between segmentation and the ground truth, run: ```bash -python evaluation.py +python util/evaluation.py ``` -You may need to edit the parameters for segmentation folder and ground truth folder. \ No newline at end of file +You may need to edit this file to specify folders for segmentation and ground truth. diff --git a/config15/test_all_class.txt b/config15/test_all_class.txt index 62376c3..4badd1f 100755 --- a/config15/test_all_class.txt +++ b/config15/test_all_class.txt @@ -1,7 +1,7 @@ [data] data_root = /home/guotwang/data/BRATS2015_Training save_folder = result15 -data_names = config15/test_names.txt +data_names = config15/test_names_temp.txt modality_postfix = [Flair, T1, T1c, T2] file_postfix = mha diff --git a/config15/test_names_temp.txt b/config15/test_names_temp.txt new file mode 100644 index 0000000..3d12cea --- /dev/null +++ b/config15/test_names_temp.txt @@ -0,0 +1,2 @@ +HGG/brats_tcia_pat417_0001 +HGG/brats_tcia_pat205_0001 \ No newline at end of file diff --git a/config15/test_wt.txt b/config15/test_wt.txt index 1226bcf..8f5b62a 100755 --- a/config15/test_wt.txt +++ b/config15/test_wt.txt @@ -1,7 +1,7 @@ [data] data_root = /home/guotwang/data/BRATS2015_Training save_folder = result15 -data_names = config15/test_names.txt +data_names = config15/test_names_temp.txt modality_postfix = [Flair, T1, T1c, T2] file_postfix = mha diff --git a/config17/test_all_class.txt b/config17/test_all_class.txt index 82a57c6..887272b 100755 --- a/config17/test_all_class.txt +++ b/config17/test_all_class.txt @@ -1,7 +1,7 @@ [data] data_root = /home/guotwang/data/Brats17TrainingData save_folder = result17 -data_names = config17/test_names.txt +data_names = config17/test_names_temp.txt modality_postfix = [flair, t1, t1ce, t2] file_postfix = nii.gz diff --git a/config17/test_names_temp.txt b/config17/test_names_temp.txt new file mode 100755 index 0000000..52686f5 --- /dev/null +++ b/config17/test_names_temp.txt @@ -0,0 +1,2 @@ +HGG/Brats17_CBICA_ATX_1 +HGG/Brats17_CBICA_AXN_1 \ No newline at end of file diff --git a/config17/test_wt.txt b/config17/test_wt.txt index b9208de..ad3dae6 100755 --- a/config17/test_wt.txt +++ b/config17/test_wt.txt @@ -1,7 +1,7 @@ [data] data_root = /home/guotwang/data/Brats17TrainingData save_folder = result17 -data_names = config17/test_names.txt +data_names = config17/test_names_temp.txt modality_postfix = [flair, t1, t1ce, t2] file_postfix = nii.gz