a b/flair-segmentation/README.md
1
# FLAIR abnormality segmentation in brain MRI
2
3
This folder contains an implementation of a FLAIR abnormality segmentation in brain MRI using U-Net like architecture.
4
It can be used to preprocess MRI images, train the network for tumor segmentation or obtain segmentation predictions of  FLAIR abnormality in a custom dataset (not expected to work outstandingly well without prior fine-tuning).
5
6
### Results
7
The results presented here refer to the network fine-tuned for 64 epochs and initialized with the weights for skull stripping task based on FLAIR modality only.
8
This training procedure requires to have the same training/test split for both FLAIR segmentaiton and skull stripping tasks.
9
It was not used in the application described in our paper.
10
Still, it makes the developed architecture, trained weights, and code more widely applicable.
11
12
Some qualitative results for the worst (80.74% DSC) and best case (92.37% DSC) from the test set before postprocessing.
13
Blue outline corresponds to ground truth and red to automatic segmentation output.
14
Images show FLAIR modality after preprocessing and skull stripping.
15
16
| Worst Case | Best Case |
17
|:----------:|:---------:|
18
|![Worst case](DU_7306.gif)|![Best case](DU_5851.gif)|
19
20
The average Dice similarity coefficient (DSC) for this split was 88.37%.
21
The distribution of DCS is shown below.
22
23
![DCS](DSC.png)
24
25
Training log for a random 5 test cases split (the same as in skull stripping):
26
27
![training](training.png)
28
29
### Usage
30
31
#### Preprocessing
32
You need to have a folder with images preprocessed using provided matlab function `preprocessing3D.m`.
33
It rescales them to have spacial dimensions 256x256 and performs contrast normalization.
34
The preprocessing is done for a 3D volume of slices yet for each MRI modality separately.
35
Refer to the documentation of `preprocessing3D.m` function for more details.
36
The main requirement for the following steps is to have image names in format `<case_id>_<slice_number>.tif` and corresponding masks named `<case_id>_<slice_number>_mask.tif`.
37
38
#### Training
39
The training script `train.py` has variables defined at the top that you need to set:
40
41
- `train_images_path` - folder containing training images
42
- `valid_images_path` - folder containing validation images
43
    
44
Other variables can be changed to adjust some training parameters.
45
One of them, `init_weights_path`, allows to initialize the network with pre-trained weights, e.g. provided by us or from the model trained for skull stripping (in this case make sure to have the same training/test splits for both tasks).
46
The models described in our paper were trained from scratch.
47
48
Then, run the training using
49
```
50
python train.py
51
```
52
53
#### Testing
54
To run the inference, you need to set up some variables defined at the top of the `test.py` script:
55
56
- `weights_path` - path to the trained weights
57
- `train_images_path` - folder containing training images to compute the mean and standard deviation for data normalization; if you pass your own mean and standard deviation to the `test` function, this variable is not used
58
- `test_images_path` - folder with test images for prediction; it must contain corresponding mask files as well, however, they can be dummy (all zeros)
59
- `predictions_path` - folder for saving predicted and ground truth segmentation outlines (will be created if it doesn't exist)
60
61
When all variables are set up, run the inference using
62
```
63
python test.py
64
```
65
66
If you want to use our trained weights for inference, you should use mean and standard deviation values for normalization computed on our training set.
67
They are the default parameter values used in the `test` function of `test.py` script.
68
69
Trained weights can be downloaded using provided script
70
```
71
./download_weights.sh 
72
```
73
74
### Troubleshooting
75
76
#### AttributeError: 'module' object has no attribute 'rolling_count'
77
78
Try updating dask (related issue: [tflearn/issues/766](https://github.com/tflearn/tflearn/issues/766)):
79
80
```
81
sudo pip install dask --upgrade
82
```