GitHub - lee-zq/3DUNet-Pytorch: 3DUNet implemented with pytorch3DUNet implemented with pytorch. Contribute to lee-zq/3DUNet-Pytorch development by creating an account on GitHub.https://github.com/lee-zq/3DUNet-Pytorch
数据集:LITS2017肝脏肿瘤分割挑战数据集
步骤:预处理 => 训练 => 测试
预处理:根目录下建立文件夹raw_dataset 和fixed_data文件夹
raw_dataset:
├── train # (28~46)
│ ├── ct
│ │ ├── volume-27.nii
│ │ ├── volume-28.nii ...
│ └── label
│ ├── segmentation-27.nii
│ ├── segmentation-28.nii ...
│
├── test # 0~27和47~131
│ ├── ct
│ │ ├── volume-0.nii
│ │ ├── volume-1.nii ...
│ └── label
│ ├── segmentation-0.nii
│ ├── segmentation-1.nii ...
fixed_data:
├── ct
│
├── label
修改preprocess_LiTS.py文件,并运行
if __name__ == '__main__':
raw_dataset_path = r'G:\B\3DUNet\raw_dataset\train'
fixed_dataset_path = r'G:\B\3DUNet\fixed_data'
训练:修改config.py文件中 dataset_path的路径
parser.add_argument('--dataset_path',default = r'G:\B\3DUNet\fixed_data',help='fixed trainset root path')
修改train.py的79行
model = torch.nn.DataParallel(model, device_ids=[0]).cuda() #单GPU
#model = torch.nn.DataParallel(model, device_ids=args.gpu_id) # multi-GPU
修改models/ResUNet.py 137行--159行中的
nn.Upsample(scale_factor=(k, x, x), mode='trilinear', align_corners=False)
改为nn.Upsample(scale_factor=(k, 0.5x, 0.5x), mode='trilinear', align_corners=False)
运行python train.py --save model_name得到模型best_model.pth保存在experiments/model_name中
预测:
将上述 models/ResUNet.py 137行--159行的(k, 0.5x, 0.5x)修改回去
改config.py测试集路径和模型路径
parser.add_argument('--test_data_path',default = r'G:\B\3DUNet\raw_dataset\test',help='Testset path')
parser.add_argument('--save',default='model_name',help='save path of trained model')
改test.py50行
model = torch.nn.DataParallel(model, device_ids=[0]).cuda() #单GPU
#model = torch.nn.DataParallel(model, device_ids=args.gpu_id) # multi-GPU
运行test.py得到的结果保存在model_name/result中