|
{ |
|
"imports": [ |
|
"$import pandas as pd", |
|
"$import os", |
|
"$import ignite" |
|
], |
|
"bundle_root": "/wokspace/model-zoo/models/prostate_mri_anatomy", |
|
"ckpt_dir": "$@bundle_root + '/models'", |
|
"output_dir": "$@bundle_root + '/eval'", |
|
"dataset_dir": "/workspace/data/prostate158/prostate158_train/", |
|
"images": "$list(@dataset_dir + pd.read_csv(@dataset_dir + 'train.csv').t2)", |
|
"labels": "$list(@dataset_dir + pd.read_csv(@dataset_dir + 'train.csv').t2_anatomy_reader1)", |
|
"val_images": "$list(@dataset_dir + pd.read_csv(@dataset_dir + 'valid.csv').t2)", |
|
"val_labels": "$list(@dataset_dir + pd.read_csv(@dataset_dir + 'valid.csv').t2_anatomy_reader1)", |
|
"val_interval": 5, |
|
"device": "$torch.device('cuda:0' if torch.cuda.is_available() else 'cpu')", |
|
"network_def": { |
|
"_target_": "UNet", |
|
"spatial_dims": 3, |
|
"in_channels": 1, |
|
"out_channels": 3, |
|
"channels": [ |
|
16, |
|
32, |
|
64, |
|
128, |
|
256, |
|
512 |
|
], |
|
"strides": [ |
|
2, |
|
2, |
|
2, |
|
2, |
|
2 |
|
], |
|
"num_res_units": 4, |
|
"norm": "batch", |
|
"act": "prelu", |
|
"dropout": 0.15 |
|
}, |
|
"network": "$@network_def.to(@device)", |
|
"loss": { |
|
"_target_": "DiceFocalLoss", |
|
"to_onehot_y": true, |
|
"softmax": true, |
|
"include_background": false |
|
}, |
|
"optimizer": { |
|
"_target_": "Novograd", |
|
"params": "$@network.parameters()", |
|
"lr": 0.001, |
|
"amsgrad": true, |
|
"weight_decay": 0.01 |
|
}, |
|
"train": { |
|
"deterministic_transforms": [ |
|
{ |
|
"_target_": "LoadImaged", |
|
"keys": [ |
|
"image", |
|
"label" |
|
] |
|
}, |
|
{ |
|
"_target_": "EnsureChannelFirstd", |
|
"keys": [ |
|
"image", |
|
"label" |
|
] |
|
}, |
|
{ |
|
"_target_": "Orientationd", |
|
"keys": [ |
|
"image", |
|
"label" |
|
], |
|
"axcodes": "RAS" |
|
}, |
|
{ |
|
"_target_": "Spacingd", |
|
"keys": [ |
|
"image", |
|
"label" |
|
], |
|
"pixdim": [ |
|
0.5, |
|
0.5, |
|
0.5 |
|
], |
|
"mode": [ |
|
"bilinear", |
|
"nearest" |
|
] |
|
}, |
|
{ |
|
"_target_": "ScaleIntensityd", |
|
"keys": "image", |
|
"minv": 0, |
|
"maxv": 1 |
|
}, |
|
{ |
|
"_target_": "NormalizeIntensityd", |
|
"keys": "image" |
|
}, |
|
{ |
|
"_target_": "EnsureTyped", |
|
"keys": [ |
|
"image", |
|
"label" |
|
] |
|
} |
|
], |
|
"random_transforms": [ |
|
{ |
|
"_target_": "RandAdjustContrastd", |
|
"keys": "image", |
|
"prob": 0.15, |
|
"gamma": 2.0 |
|
}, |
|
{ |
|
"_target_": "RandGaussianNoised", |
|
"keys": "image", |
|
"prob": 0.15, |
|
"mean": 0.1, |
|
"std": 0.25 |
|
}, |
|
{ |
|
"_target_": "RandAffined", |
|
"keys": [ |
|
"image", |
|
"label" |
|
], |
|
"prob": 0.15, |
|
"rotate_range": 5, |
|
"shear_range": 0.5, |
|
"translate_range": 25 |
|
}, |
|
{ |
|
"_target_": "RandBiasFieldd", |
|
"keys": "image", |
|
"prob": 0.15, |
|
"coeff_range": [ |
|
0.0, |
|
0.01 |
|
], |
|
"degree": 10 |
|
}, |
|
{ |
|
"_target_": "Rand3DElasticd", |
|
"keys": [ |
|
"image", |
|
"label" |
|
], |
|
"prob": 0.15, |
|
"magnitude_range": [ |
|
0.5, |
|
1.5 |
|
], |
|
"rotate_range": 5, |
|
"shear_range": 0.5, |
|
"sigma_range": [ |
|
0.5, |
|
1.5 |
|
], |
|
"translate_range": 25 |
|
}, |
|
{ |
|
"_target_": "RandZoomd", |
|
"keys": [ |
|
"image", |
|
"label" |
|
], |
|
"prob": 0.15, |
|
"max": 1.1, |
|
"min": 0.9 |
|
}, |
|
{ |
|
"_target_": "RandCropByPosNegLabeld", |
|
"keys": [ |
|
"image", |
|
"label" |
|
], |
|
"label_key": "label", |
|
"spatial_size": [ |
|
96, |
|
96, |
|
96 |
|
], |
|
"pos": 1, |
|
"neg": 1, |
|
"num_samples": 4, |
|
"image_key": "image", |
|
"image_threshold": 0 |
|
}, |
|
{ |
|
"_target_": "RandShiftIntensityd", |
|
"keys": "image", |
|
"prob": 0.15, |
|
"offsets": 0.2 |
|
} |
|
], |
|
"preprocessing": { |
|
"_target_": "Compose", |
|
"transforms": "$@train#deterministic_transforms + @train#random_transforms" |
|
}, |
|
"dataset": { |
|
"_target_": "PersistentDataset", |
|
"data": "$[{'image': i, 'label': l} for i, l in zip(@images, @labels)]", |
|
"transform": "@train#preprocessing", |
|
"cache_dir": "$@bundle_root + '/cache'" |
|
}, |
|
"dataloader": { |
|
"_target_": "DataLoader", |
|
"dataset": "@train#dataset", |
|
"batch_size": 2, |
|
"shuffle": true, |
|
"num_workers": 4 |
|
}, |
|
"inferer": { |
|
"_target_": "SimpleInferer" |
|
}, |
|
"postprocessing": { |
|
"_target_": "Compose", |
|
"transforms": [ |
|
{ |
|
"_target_": "Activationsd", |
|
"keys": "pred", |
|
"softmax": true |
|
}, |
|
{ |
|
"_target_": "AsDiscreted", |
|
"keys": [ |
|
"pred", |
|
"label" |
|
], |
|
"argmax": [ |
|
true, |
|
false |
|
], |
|
"to_onehot": 3 |
|
} |
|
] |
|
}, |
|
"handlers": [ |
|
{ |
|
"_target_": "ValidationHandler", |
|
"validator": "@validate#evaluator", |
|
"epoch_level": true, |
|
"interval": "@val_interval" |
|
}, |
|
{ |
|
"_target_": "StatsHandler", |
|
"tag_name": "train_loss", |
|
"output_transform": "$monai.handlers.from_engine(['loss'], first=True)" |
|
}, |
|
{ |
|
"_target_": "TensorBoardStatsHandler", |
|
"log_dir": "@output_dir", |
|
"tag_name": "train_loss", |
|
"output_transform": "$monai.handlers.from_engine(['loss'], first=True)" |
|
} |
|
], |
|
"key_metric": { |
|
"train_dice": { |
|
"_target_": "MeanDice", |
|
"include_background": false, |
|
"output_transform": "$monai.handlers.from_engine(['pred', 'label'])" |
|
} |
|
}, |
|
"trainer": { |
|
"_target_": "SupervisedTrainer", |
|
"max_epochs": 100, |
|
"device": "@device", |
|
"train_data_loader": "@train#dataloader", |
|
"network": "@network", |
|
"loss_function": "@loss", |
|
"optimizer": "@optimizer", |
|
"inferer": "@train#inferer", |
|
"postprocessing": "@train#postprocessing", |
|
"key_train_metric": "@train#key_metric", |
|
"train_handlers": "@train#handlers", |
|
"amp": true |
|
} |
|
}, |
|
"validate": { |
|
"preprocessing": { |
|
"_target_": "Compose", |
|
"transforms": "%train#deterministic_transforms" |
|
}, |
|
"dataset": { |
|
"_target_": "PersistentDataset", |
|
"data": "$[{'image': i, 'label': l} for i, l in zip(@val_images, @val_labels)]", |
|
"transform": "@validate#preprocessing", |
|
"cache_dir": "$@bundle_root + '/cache'" |
|
}, |
|
"dataloader": { |
|
"_target_": "DataLoader", |
|
"dataset": "@validate#dataset", |
|
"batch_size": 1, |
|
"shuffle": false, |
|
"num_workers": 4 |
|
}, |
|
"inferer": { |
|
"_target_": "SlidingWindowInferer", |
|
"roi_size": [ |
|
96, |
|
96, |
|
96 |
|
], |
|
"sw_batch_size": 16, |
|
"overlap": 0.5 |
|
}, |
|
"postprocessing": "%train#postprocessing", |
|
"handlers": [ |
|
{ |
|
"_target_": "StatsHandler", |
|
"iteration_log": false |
|
}, |
|
{ |
|
"_target_": "TensorBoardStatsHandler", |
|
"log_dir": "@output_dir", |
|
"iteration_log": false |
|
}, |
|
{ |
|
"_target_": "CheckpointSaver", |
|
"save_dir": "@ckpt_dir", |
|
"save_dict": { |
|
"model": "@network" |
|
}, |
|
"save_key_metric": true, |
|
"key_metric_filename": "model.pt" |
|
} |
|
], |
|
"key_metric": { |
|
"val_mean_dice": { |
|
"_target_": "MeanDice", |
|
"include_background": false, |
|
"output_transform": "$monai.handlers.from_engine(['pred', 'label'])" |
|
} |
|
}, |
|
"additional_metrics": { |
|
"val_hausdorff_distance": { |
|
"_target_": "HausdorffDistance", |
|
"include_background": false, |
|
"reduction": "mean", |
|
"output_transform": "$monai.handlers.from_engine(['pred', 'label'])" |
|
}, |
|
"val_surface_distance": { |
|
"_target_": "SurfaceDistance", |
|
"include_background": false, |
|
"reduction": "mean", |
|
"output_transform": "$monai.handlers.from_engine(['pred', 'label'])" |
|
} |
|
}, |
|
"evaluator": { |
|
"_target_": "SupervisedEvaluator", |
|
"device": "@device", |
|
"val_data_loader": "@validate#dataloader", |
|
"network": "@network", |
|
"inferer": "@validate#inferer", |
|
"postprocessing": "@validate#postprocessing", |
|
"key_val_metric": "@validate#key_metric", |
|
"additional_metrics": "@validate#additional_metrics", |
|
"val_handlers": "@validate#handlers", |
|
"amp": true |
|
} |
|
}, |
|
"training": [ |
|
"$monai.utils.set_determinism(seed=42)", |
|
"$setattr(torch.backends.cudnn, 'benchmark', True)", |
|
"$@train#trainer.run()" |
|
] |
|
} |
|
|