{ "displayable_configs": { "highres": true, "init_LR": 0.0001 }, "imports": [ "$import glob", "$import os", "$import ignite" ], "bundle_root": ".", "ckpt_dir": "$@bundle_root + '/models'", "output_dir": "$@bundle_root + '/eval'", "dataset_dir": "sampledata", "images": "$list(sorted(glob.glob(@dataset_dir + '/imagesTr/*.nii.gz')))", "labels": "$list(sorted(glob.glob(@dataset_dir + '/labelsTr/*.nii.gz')))", "highres": true, "val_interval": 20, "init_LR": 0.0001, "batch_size": 4, "pixdim": "$[1.5, 1.5, 1.5] if @displayable_configs#highres else [3.0, 3.0, 3.0]", "modelname": "$'model.pt' if @displayable_configs#highres else 'model_lowres.pt'", "device": "$torch.device('cuda:0' if torch.cuda.is_available() else 'cpu')", "network_def": { "_target_": "SegResNet", "spatial_dims": 3, "in_channels": 1, "out_channels": 105, "init_filters": 32, "blocks_down": [ 1, 2, 2, 4 ], "blocks_up": [ 1, 1, 1 ], "dropout_prob": 0.2 }, "network": "$@network_def.to(@device)", "loss": { "_target_": "DiceCELoss", "to_onehot_y": true, "softmax": true }, "optimizer": { "_target_": "torch.optim.AdamW", "params": "$@network.parameters()", "lr": "@displayable_configs#init_LR", "weight_decay": 1e-05 }, "train": { "deterministic_transforms": [ { "_target_": "LoadImaged", "keys": [ "image", "label" ] }, { "_target_": "EnsureChannelFirstd", "keys": [ "image", "label" ] }, { "_target_": "EnsureTyped", "keys": [ "image", "label" ] }, { "_target_": "Orientationd", "keys": [ "image", "label" ], "axcodes": "RAS" }, { "_target_": "Spacingd", "keys": [ "image", "label" ], "pixdim": "@pixdim", "mode": [ "bilinear", "nearest" ] }, { "_target_": "NormalizeIntensityd", "keys": "image", "nonzero": true }, { "_target_": "CropForegroundd", "keys": [ "image", "label" ], "source_key": "image", "margin": 10, "k_divisible": [ 96, 96, 96 ] }, { "_target_": "GaussianSmoothd", "keys": [ "image" ], "sigma": 0.4 }, { "_target_": "ScaleIntensityd", "keys": "image", "minv": -1.0, "maxv": 1.0 }, { "_target_": "EnsureTyped", "keys": [ "image", "label" ] } ], "random_transforms": [ { "_target_": "RandSpatialCropd", "keys": [ "image", "label" ], "roi_size": [ 96, 96, 96 ], "random_size": false } ], "preprocessing": { "_target_": "Compose", "transforms": "$@train#deterministic_transforms + @train#random_transforms" }, "dataset": { "_target_": "CacheDataset", "data": "$[{'image': i, 'label': l} for i, l in zip(@images[:-10], @labels[:-10])]", "transform": "@train#preprocessing", "cache_rate": 0.4, "num_workers": 4 }, "dataloader": { "_target_": "DataLoader", "dataset": "@train#dataset", "batch_size": "@batch_size", "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": 105 } ] }, "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_accuracy": { "_target_": "ignite.metrics.Accuracy", "output_transform": "$monai.handlers.from_engine(['pred', 'label'])" } }, "trainer": { "_target_": "SupervisedTrainer", "max_epochs": 4000, "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": [ { "_target_": "LoadImaged", "keys": [ "image", "label" ] }, { "_target_": "EnsureChannelFirstd", "keys": [ "image", "label" ] }, { "_target_": "EnsureTyped", "keys": [ "image", "label" ] }, { "_target_": "Orientationd", "keys": [ "image", "label" ], "axcodes": "RAS" }, { "_target_": "Spacingd", "keys": [ "image", "label" ], "pixdim": "@pixdim", "mode": [ "bilinear", "nearest" ] }, { "_target_": "NormalizeIntensityd", "keys": "image", "nonzero": true }, { "_target_": "CropForegroundd", "keys": [ "image", "label" ], "source_key": "image", "margin": 10, "k_divisible": [ 96, 96, 96 ] }, { "_target_": "GaussianSmoothd", "keys": [ "image" ], "sigma": 0.4 }, { "_target_": "ScaleIntensityd", "keys": "image", "minv": -1.0, "maxv": 1.0 }, { "_target_": "CenterSpatialCropd", "keys": [ "image", "label" ], "roi_size": [ 160, 160, 160 ] } ] }, "postprocessing": { "_target_": "Compose", "transforms": [ { "_target_": "Activationsd", "keys": "pred", "softmax": true }, { "_target_": "AsDiscreted", "keys": [ "pred", "label" ], "argmax": [ true, false ], "to_onehot": 105 } ] }, "dataset": { "_target_": "Dataset", "data": "$[{'image': i, 'label': l} for i, l in zip(@images[-10:], @labels[-10:])]", "transform": "@validate#preprocessing" }, "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": 1, "overlap": 0.25 }, "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": "@modelname" } ], "key_metric": { "val_mean_dice": { "_target_": "MeanDice", "include_background": false, "output_transform": "$monai.handlers.from_engine(['pred', 'label'])" } }, "additional_metrics": { "val_accuracy": { "_target_": "ignite.metrics.Accuracy", "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 } }, "initialize": [ "$monai.utils.set_determinism(seed=123)", "$setattr(torch.backends.cudnn, 'benchmark', True)" ], "run": [ "$@train#trainer.run()" ] }