Pytorch_Medical_Segmention_Template
Pytorch_Medical_Segmention_Template copied to clipboard
This is a pytorch project template about medical segmentation
Pytorch_Medical_Segmention_Template
Introduction
This project is a medical image segmentation template based on Pytorch implementation, which implements the basic and even most of the functions you need in medical image segmentation experiments. Such as data processing, the design of loss, tool files, save and visualization of log, model files, training ,validation, test and project configuration.
Folder
Dataset: the folder where dataset is placed.Linear_lesion_Code: the folder where model and model environment code are placed,Linear_lesionis the name of task. Many different models can be put in this folder, for example, I only putUNet.dataset: the file of data preprocessing.model: model files.utils: utils files(include many utils)config.py: some configuration about project parameters.loss.py: some custom loss functionsutils.py: some definitions of evaluation indicators
metric.py: offline evaluation functiontrain.py: training, validation and test function.
Pretrain_model: pretriand encoder model,for example,resnet34.
Prerequisites
- PyTorch 1.0
conda install torch torchvision
- tqdm
conda install tqdm
- imgaug
conda install six numpy scipy Pillow matplotlib scikit-image opencv-python imageio Shapelyconda install imgaug
Supported functions:
- Unet-based single class segmentation. (Unet parameters are variable, you can adjust the channel reduction factor (feature_scale) according to your actual needs)
- Automatically realize N-fold cross-validation
- Employs Dice+BCE as a loss function
- The optimizer is SGD, and the learning strategy is 'ploy'
- Evaluation indicators: Acc, Dice, Jaccard, Sen, Spe
- Automatically save the N-fold checkpoint file
- Automatically save the N-fold tensorboard log. Support visual comparison of multiple experiments before and after, just copy the UNet folder and rename it to: "UNet_xxxxx", then modify it on this.
What you should do:
Step 1:
Create a fixed-format data folder under the Dataset folder (using the Linear_lesion data as an example, f1, f2, f3.. is the folder name, which stores each fold(N-flod) image):
─Linear_lesion
|
|─img
│ ├─f1
│ ├─f2
│ ├─f3
│ ├─f4
│ └─f5
└─mask
├─f1
├─f2
├─f3
├─f4
└─f5
Step 2:
Modify Pytorch_Project_template\Linear_lesion_Code\UNet\utils\config.py according to your needs(rows marked with '*' require special attention)
Step 3:
Run the train.py file of Pytorch_Project_template\Linear_lesion_Code\UNet