Skip to content

Commit

Permalink
Merge branch 'datasetnp' into 'master'
Browse files Browse the repository at this point in the history
Datasetnp

See merge request !1
  • Loading branch information
Guotai Wang committed Jan 13, 2018
2 parents 85be490 + b9b8c9c commit 8efe825
Show file tree
Hide file tree
Showing 28 changed files with 1,615 additions and 1,082 deletions.
93 changes: 93 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# 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 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

If you use any resources in this repository, please cite the following papers:

* [1] Guotai Wang, Wenqi Li, Sebastien Ourselin, Tom Vercauteren. "Automatic Brain Tumor Segmentation using Cascaded Anisotropic Convolutional Neural Networks." arXiv preprint arXiv:1710.04043 (2017).
https://arxiv.org/abs/1709.00382

* [2] Eli Gibson*, Wenqi Li*, Carole Sudre, Lucas Fidon, Dzhoshkun I. Shakir, Guotai Wang, Zach Eaton-Rosen, Robert Gray, Tom Doel, Yipeng Hu, Tom Whyntie, Parashkev Nachev, Marc Modat, Dean C. Barratt, Sébastien Ourselin, M. Jorge Cardoso^, Tom Vercauteren^.
"NiftyNet: a deep-learning platform for medical imaging." arXiv preprint arXiv: 1709.03485 (2017). https://arxiv.org/abs/1709.03485

![A slice from BRATS17](./data/example_seg.png)

An example of brain tumor segmentation result.

# Requirements
* A CUDA compatable GPU with memoery not less than 6GB is recommended for training. For testing only, a CUDA compatable GPU may not be required.

* Tensorflow. Install tensorflow following instructions from https://www.tensorflow.org/install/

* NiftyNet. Install it by following instructions from http://niftynet.readthedocs.io/en/dev/installation.html or simply typing:
```bash
pip install niftynet
```

* BraTS 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`.

* 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:

```bash
python test.py config/test_wt.txt
```
* Obtain segmentation of all the tumor subregions, run:

```bash
python test.py config/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.

* 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
```
* 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
```
* 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
```

## 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
set the value of model_file to your own model files. Run:
```bash
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
```
You may need to edit the parameters for segmentation folder and ground truth folder.
91 changes: 91 additions & 0 deletions config/test_all_class.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
[data]
data_root = [data/Brats17ValidationData_renamed]
data_names =

[network1ax]
net_type = MSNet
net_name = MSNet_WT32
downsample_twice = True
data_shape = [19, 180, 160, 4]
label_shape = [11, 180, 160, 1]
class_num = 2
model_file = model_pretrain/msnet_wt32_20000.ckpt

[network1sg]
net_type = MSNet
net_name = MSNet_WT32sg
downsample_twice = True
data_shape = [19, 160, 180, 4]
label_shape = [11, 160, 180, 1]
class_num = 2
model_file = model_pretrain/msnet_wt32sg_20000.ckpt

[network1cr]
net_type = MSNet
net_name = MSNet_WT32cr
downsample_twice = True
data_shape = [19, 160, 160, 4]
label_shape = [11, 160, 160, 1]
class_num = 2
model_file = model_pretrain/msnet_wt32cr_20000.ckpt


[network2ax]
net_type = MSNet
net_name = MSNet_TC32
downsample_twice = True
data_shape = [19, 96, 96, 4]
label_shape = [11, 96, 96, 1]
class_num = 2
model_file = model_pretrain/msnet_tc32_20000.ckpt

[network2sg]
net_type = MSNet
net_name = MSNet_TC32sg
downsample_twice = True
data_shape = [19, 96, 96, 4]
label_shape = [11, 96, 96, 1]
class_num = 2
model_file = model_pretrain/msnet_tc32sg_20000.ckpt

[network2cr]
net_type = MSNet
net_name = MSNet_TC32cr
downsample_twice = True
data_shape = [19, 96, 96, 4]
label_shape = [11, 96, 96, 1]
class_num = 2
model_file = model_pretrain/msnet_tc32cr_20000.ckpt

[network3ax]
net_type = MSNet
net_name = MSNet_EN32
downsample_twice = False
data_shape = [19, 96, 96, 4]
label_shape = [11, 96, 96, 1]
class_num = 2
model_file = model_pretrain/msnet_en32_20000.ckpt

[network3sg]
net_type = MSNet
net_name = MSNet_EN32sg
downsample_twice = False
data_shape = [19, 96, 96, 4]
label_shape = [11, 96, 96, 1]
class_num = 2
model_file = model_pretrain/msnet_en32sg_20000.ckpt

[network3cr]
net_type = MSNet
net_name = MSNet_EN32cr
downsample_twice = False
data_shape = [19, 96, 96, 4]
label_shape = [11, 96, 96, 1]
class_num = 2
model_file = model_pretrain/msnet_en32cr_20000.ckpt

[testing]
test_slice_direction = all
label_convert_source = [0, 1, 2, 3]
label_convert_target = [0, 1, 2, 4]
save_folder = results
20 changes: 20 additions & 0 deletions config/test_names_example.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
HGG/Brats17_CBICA_ATX_1
HGG/Brats17_CBICA_AXN_1
HGG/Brats17_TCIA_491_1
HGG/Brats17_CBICA_AOZ_1
HGG/Brats17_TCIA_151_1
HGG/Brats17_2013_25_1
HGG/Brats17_TCIA_396_1
HGG/Brats17_CBICA_AQN_1
HGG/Brats17_TCIA_135_1
HGG/Brats17_TCIA_603_1
LGG/Brats17_2013_24_1
LGG/Brats17_TCIA_630_1
LGG/Brats17_TCIA_152_1
LGG/Brats17_TCIA_620_1
LGG/Brats17_TCIA_310_1
LGG/Brats17_2013_29_1
LGG/Brats17_TCIA_490_1
LGG/Brats17_TCIA_449_1
LGG/Brats17_TCIA_634_1
LGG/Brats17_TCIA_346_1
35 changes: 35 additions & 0 deletions config/test_wt.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
[data]
data_root = [data/Brats17ValidationData_renamed]
data_names =

[network1ax]
net_type = MSNet
net_name = MSNet_WT32
downsample_twice = True
data_shape = [19, 180, 160, 4]
label_shape = [11, 180, 160, 1]
class_num = 2
model_file = model_pretrain/msnet_wt32_20000.ckpt

[network1sg]
net_type = MSNet
net_name = MSNet_WT32sg
downsample_twice = True
data_shape = [19, 160, 180, 4]
label_shape = [11, 160, 180, 1]
class_num = 2
model_file = model_pretrain/msnet_wt32sg_20000.ckpt

[network1cr]
net_type = MSNet
net_name = MSNet_WT32cr
downsample_twice = True
data_shape = [19, 160, 160, 4]
label_shape = [11, 160, 160, 1]
class_num = 2
model_file = model_pretrain/msnet_wt32cr_20000.ckpt

[testing]
test_slice_direction = all
whole_tumor_only = True
save_folder = results_wt
30 changes: 30 additions & 0 deletions config/train_en_ax.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
[data]
data_root = [data/Brats17TrainingData_crop_renamed]
data_names = config/train_names_all_lggx3.txt
with_ground_truth = True
batch_size = 5
data_shape = [19, 64, 64, 4]
label_shape = [11, 64, 64, 1]
label_convert_source = [0, 1, 2, 4]
label_convert_target = [0, 0, 0, 1]
batch_slice_direction = axial
train_with_roi_patch = True
label_roi_mask = [1,4]
roi_patch_margin = 5

[network]
net_type = MSNet
net_name = MSNet_EN32
downsample_twice = False
class_num = 2

[training]
learning_rate = 1e-3
decay = 1e-7
maximal_iteration = 20000
snapshot_iteration = 5000
start_iteration = 0
test_iteration = 100
test_step = 10
model_pre_trained =
model_save_prefix = model/msnet_en32
30 changes: 30 additions & 0 deletions config/train_en_cr.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
[data]
data_root = [data/Brats17TrainingData_crop_renamed]
data_names = config/train_names_all_lggx3.txt
with_ground_truth = True
batch_size = 5
data_shape = [19, 64, 64, 4]
label_shape = [11, 64, 64, 1]
label_convert_source = [0, 1, 2, 4]
label_convert_target = [0, 0, 0, 1]
batch_slice_direction = coronal
train_with_roi_patch = True
label_roi_mask = [1,4]
roi_patch_margin = 5

[network]
net_type = MSNet
net_name = MSNet_EN32cr
downsample_twice = False
class_num = 2

[training]
learning_rate = 1e-3
decay = 1e-7
maximal_iteration = 20000
snapshot_iteration = 5000
start_iteration = 0
test_iteration = 100
test_step = 10
model_pre_trained =
model_save_prefix = model/msnet_en32cr
30 changes: 30 additions & 0 deletions config/train_en_sg.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
[data]
data_root = [data/Brats17TrainingData_crop_renamed]
data_names = config/train_names_all_lggx3.txt
with_ground_truth = True
batch_size = 5
data_shape = [19, 64, 64, 4]
label_shape = [11, 64, 64, 1]
label_convert_source = [0, 1, 2, 4]
label_convert_target = [0, 0, 0, 1]
batch_slice_direction = sagittal
train_with_roi_patch = True
label_roi_mask = [1,4]
roi_patch_margin = 5

[network]
net_type = MSNet
net_name = MSNet_EN32sg
downsample_twice = False
class_num = 2

[training]
learning_rate = 1e-3
decay = 1e-7
maximal_iteration = 20000
snapshot_iteration = 5000
start_iteration = 0
test_iteration = 100
test_step = 10
model_pre_trained =
model_save_prefix = model/msnet_en32sg
Loading

0 comments on commit 8efe825

Please sign in to comment.