|
a |
|
b/monai 0.5.0/deprecated/README.md |
|
|
1 |
 |
|
|
2 |
# SALMON v.2: Segmentation deep learning ALgorithm based on MONai toolbox |
|
|
3 |
- SALMON is a computational toolbox for segmentation using neural networks (3D patches-based segmentation) |
|
|
4 |
- SALMON is based on NN-UNET and MONAI: PyTorch-based, open-source frameworks for deep learning in healthcare imaging. |
|
|
5 |
(https://github.com/Project-MONAI/MONAI) |
|
|
6 |
(https://github.com/MIC-DKFZ/nnUNet) |
|
|
7 |
|
|
|
8 |
This is my "open-box" version if I want to modify the parameters for some particular task, while the two above are hard-coded. |
|
|
9 |
|
|
|
10 |
******************************************************************************* |
|
|
11 |
## Requirements |
|
|
12 |
We download the official MONAI DockerHub, with the latest MONAI version. Please visit https://docs.monai.io/en/latest/installation.html |
|
|
13 |
Additional packages can be installed with "pip install -r requirements.txt" |
|
|
14 |
******************************************************************************* |
|
|
15 |
## Python scripts and their function |
|
|
16 |
|
|
|
17 |
- organize_folder_structure.py: Organize the data in the folder structure (training,validation,testing) for the network. Labels are resampled and resized to the corresponding image, to avoid conflicts. |
|
|
18 |
|
|
|
19 |
- init.py: List of options used to train the network. |
|
|
20 |
|
|
|
21 |
- check_loader_patches: Shows example of patches fed to the network during the training. |
|
|
22 |
|
|
|
23 |
- networks.py: The architecture available for segmentation is a nn-Unet. |
|
|
24 |
|
|
|
25 |
- train.py: Runs the training |
|
|
26 |
|
|
|
27 |
- predict_single_image.py: It launches the inference on a single input image chosen by the user. |
|
|
28 |
******************************************************************************* |
|
|
29 |
## Usage |
|
|
30 |
### Folders structure: |
|
|
31 |
|
|
|
32 |
Use first "organize_folder_structure.py" to create organize the data. |
|
|
33 |
Modify the input parameters to select the two folders: images and labels folders with the dataset. |
|
|
34 |
|
|
|
35 |
. |
|
|
36 |
├── Data_folder |
|
|
37 |
| ├── CT |
|
|
38 |
| | ├── 1.nii |
|
|
39 |
| | ├── 2.nii |
|
|
40 |
| | └── 3.nii |
|
|
41 |
| ├── CT_labels |
|
|
42 |
| | ├── 1.nii |
|
|
43 |
| | ├── 2.nii |
|
|
44 |
| | └── 3.nii |
|
|
45 |
|
|
|
46 |
Data structure after running it: |
|
|
47 |
|
|
|
48 |
. |
|
|
49 |
├── Data_folder |
|
|
50 |
| ├── images |
|
|
51 |
| | ├── train |
|
|
52 |
| | | ├── image1.nii |
|
|
53 |
| | | └── image2.nii |
|
|
54 |
| | └── val |
|
|
55 |
| | | ├── image3.nii |
|
|
56 |
| | | └── image4.nii |
|
|
57 |
| | └── test |
|
|
58 |
| | | ├── image5.nii |
|
|
59 |
| | | └── image6.nii |
|
|
60 |
| ├── labels |
|
|
61 |
| | ├── train |
|
|
62 |
| | | ├── label1.nii |
|
|
63 |
| | | └── label2.nii |
|
|
64 |
| | └── val |
|
|
65 |
| | | ├── label3.nii |
|
|
66 |
| | | └── label4.nii |
|
|
67 |
| | └── test |
|
|
68 |
| | | ├── label5.nii |
|
|
69 |
| | | └── label6.nii |
|
|
70 |
|
|
|
71 |
******************************************************************************* |
|
|
72 |
### Training: |
|
|
73 |
- Modify the "init.py" to set the parameters and start the training/testing on the data. Read the descriptions for each parameter. |
|
|
74 |
- Afterwards launch the train.py for training. Tensorboard is available to monitor the training: |
|
|
75 |
|
|
|
76 |
 |
|
|
77 |
|
|
|
78 |
Sample images: on the left side the image, in the middle the result of the segmentation and on the right side the true label |
|
|
79 |
The following images show the segmentation of carotid artery from MR sequence |
|
|
80 |
|
|
|
81 |
 |
|
|
82 |
|
|
|
83 |
Sample images: on the left side the image, in the middle the result of the segmentation and on the right side the true label |
|
|
84 |
The following images show the multi-label segmentation of prostate transition zone and peripheral zone from MR sequence |
|
|
85 |
|
|
|
86 |
 |
|
|
87 |
******************************************************************************* |
|
|
88 |
### Inference: |
|
|
89 |
Launch "predict_single_image.py" to test the network. Modify the parameters in the parse section to select the path of the weights, images to infer and result. |
|
|
90 |
******************************************************************************* |
|
|
91 |
### Tips: |
|
|
92 |
- Use and modify "check_loader_patches.py" to check the patches fed during training. |
|
|
93 |
- "Organize_folder_structure.py" solves dimensionality conflicts if the label has different size and resolution of the image. Check on 3DSlicer or ITKSnap if your data are correctly centered-overlaid. |
|
|
94 |
- The "networks.py" calls the nn-Unet, which adapts itself to the input data (resolution and patches size). The script also saves the graph of you network, so you can visualize it. |
|
|
95 |
- Is it possible to add other networks, but for segmentation the U-net architecture is the state of the art. |
|
|
96 |
- During the training phase, the script crops the image background and pad the image if the post-cropping size is smaller than the patch size you set in init.py |
|
|
97 |
|
|
|
98 |
|
|
|
99 |
### Sample script inference |
|
|
100 |
- The label can be omitted (None) if you segment an unknown image. You can add the --resolution if you resampled the data during training (look at the argsparse in the code). |
|
|
101 |
```console |
|
|
102 |
python predict_single_image.py --image './Data_folder/images/train/image13.nii' --label './Data_folder/labels/train/label13.nii' --result './Data_folder/results/train/prova.nii' --weights './best_metric_model.pth' |
|
|
103 |
``` |
|
|
104 |
******************************************************************************* |
|
|
105 |
### Multi-channel segmentation: |
|
|
106 |
|
|
|
107 |
The subfolder "multi_label_segmentation_example" include the modified code for multi_labels scenario. |
|
|
108 |
The example segment the prostate (1 channel input) in the transition zone and peripheral zone (2 channels output). |
|
|
109 |
The gif files with some example images are shown above. |
|
|
110 |
|
|
|
111 |
Some note: |
|
|
112 |
- You must add an additional channel for the background. Example: 0 background, 1 prostate, 2 prostate tumor = 3 out channels in total. |
|
|
113 |
- Tensorboard can show you all segmented channels, but for now the metric is the Mean-Dice (of all channels). If you want to evaluate the Dice score for each channel you |
|
|
114 |
have to modify a bit the plot_dice function. I will do it...one day...who knows...maybe not |
|
|
115 |
- The loss is the DiceLoss + CrossEntropy. You can modify it if you want to try others (https://docs.monai.io/en/latest/losses.html#diceloss) |
|
|
116 |
|
|
|
117 |
Check more examples at https://github.com/Project-MONAI/tutorials/blob/master/3d_segmentation/spleen_segmentation_3d.ipynb. |