-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from Project-MONAI/swin_unetr_btcv
add swin_unetr bundle
- Loading branch information
Showing
10 changed files
with
790 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
{ | ||
"validate#postprocessing": { | ||
"_target_": "Compose", | ||
"transforms": [ | ||
{ | ||
"_target_": "Activationsd", | ||
"keys": "pred", | ||
"softmax": true | ||
}, | ||
{ | ||
"_target_": "Invertd", | ||
"keys": [ | ||
"pred", | ||
"label" | ||
], | ||
"transform": "@validate#preprocessing", | ||
"orig_keys": "image", | ||
"meta_key_postfix": "meta_dict", | ||
"nearest_interp": [ | ||
false, | ||
true | ||
], | ||
"to_tensor": true | ||
}, | ||
{ | ||
"_target_": "AsDiscreted", | ||
"keys": [ | ||
"pred", | ||
"label" | ||
], | ||
"argmax": [ | ||
true, | ||
false | ||
], | ||
"to_onehot": 14 | ||
}, | ||
{ | ||
"_target_": "SaveImaged", | ||
"keys": "pred", | ||
"meta_keys": "pred_meta_dict", | ||
"output_dir": "@output_dir", | ||
"resample": false, | ||
"squeeze_end_dims": true | ||
} | ||
] | ||
}, | ||
"validate#handlers": [ | ||
{ | ||
"_target_": "CheckpointLoader", | ||
"load_path": "$@ckpt_dir + '/model.pt'", | ||
"load_dict": { | ||
"model": "@network" | ||
} | ||
}, | ||
{ | ||
"_target_": "StatsHandler", | ||
"iteration_log": false | ||
}, | ||
{ | ||
"_target_": "MetricsSaver", | ||
"save_dir": "@output_dir", | ||
"metrics": [ | ||
"val_mean_dice", | ||
"val_acc" | ||
], | ||
"metric_details": [ | ||
"val_mean_dice" | ||
], | ||
"batch_transform": "$monai.handlers.from_engine(['image_meta_dict'])", | ||
"summary_ops": "*" | ||
} | ||
], | ||
"evaluating": [ | ||
"$setattr(torch.backends.cudnn, 'benchmark', True)", | ||
"$@validate#evaluator.run()" | ||
] | ||
} |
141 changes: 141 additions & 0 deletions
141
models/swin_unetr_btcv_segmentation/configs/inference.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
{ | ||
"imports": [ | ||
"$import glob", | ||
"$import os" | ||
], | ||
"bundle_root": "/workspace/MONAI_Bundle/swin_unetr_btcv_segmentation/", | ||
"output_dir": "$@bundle_root + '/eval'", | ||
"dataset_dir": "/dataset/dataset0", | ||
"datalist": "$list(sorted(glob.glob(@dataset_dir + '/imagesTs/*.nii.gz')))", | ||
"device": "$torch.device('cuda:0' if torch.cuda.is_available() else 'cpu')", | ||
"network_def": { | ||
"_target_": "SwinUNETR", | ||
"spatial_dims": 3, | ||
"img_size": 96, | ||
"in_channels": 1, | ||
"out_channels": 14, | ||
"feature_size": 48, | ||
"use_checkpoint": true | ||
}, | ||
"network": "$@network_def.to(@device)", | ||
"preprocessing": { | ||
"_target_": "Compose", | ||
"transforms": [ | ||
{ | ||
"_target_": "LoadImaged", | ||
"keys": "image" | ||
}, | ||
{ | ||
"_target_": "EnsureChannelFirstd", | ||
"keys": "image" | ||
}, | ||
{ | ||
"_target_": "Orientationd", | ||
"keys": "image", | ||
"axcodes": "RAS" | ||
}, | ||
{ | ||
"_target_": "Spacingd", | ||
"keys": "image", | ||
"pixdim": [ | ||
1.5, | ||
1.5, | ||
2.0 | ||
], | ||
"mode": "bilinear" | ||
}, | ||
{ | ||
"_target_": "ScaleIntensityRanged", | ||
"keys": "image", | ||
"a_min": -175, | ||
"a_max": 250, | ||
"b_min": 0.0, | ||
"b_max": 1.0, | ||
"clip": true | ||
}, | ||
{ | ||
"_target_": "EnsureTyped", | ||
"keys": "image" | ||
} | ||
] | ||
}, | ||
"dataset": { | ||
"_target_": "Dataset", | ||
"data": "$[{'image': i} for i in @datalist]", | ||
"transform": "@preprocessing" | ||
}, | ||
"dataloader": { | ||
"_target_": "DataLoader", | ||
"dataset": "@dataset", | ||
"batch_size": 1, | ||
"shuffle": false, | ||
"num_workers": 4 | ||
}, | ||
"inferer": { | ||
"_target_": "SlidingWindowInferer", | ||
"roi_size": [ | ||
96, | ||
96, | ||
96 | ||
], | ||
"sw_batch_size": 4, | ||
"overlap": 0.5 | ||
}, | ||
"postprocessing": { | ||
"_target_": "Compose", | ||
"transforms": [ | ||
{ | ||
"_target_": "Activationsd", | ||
"keys": "pred", | ||
"softmax": true | ||
}, | ||
{ | ||
"_target_": "Invertd", | ||
"keys": "pred", | ||
"transform": "@preprocessing", | ||
"orig_keys": "image", | ||
"meta_key_postfix": "meta_dict", | ||
"nearest_interp": false, | ||
"to_tensor": true | ||
}, | ||
{ | ||
"_target_": "AsDiscreted", | ||
"keys": "pred", | ||
"argmax": true | ||
}, | ||
{ | ||
"_target_": "SaveImaged", | ||
"keys": "pred", | ||
"meta_keys": "pred_meta_dict", | ||
"output_dir": "@output_dir" | ||
} | ||
] | ||
}, | ||
"handlers": [ | ||
{ | ||
"_target_": "CheckpointLoader", | ||
"load_path": "$@bundle_root + '/models/model.pt'", | ||
"load_dict": { | ||
"model": "@network" | ||
} | ||
}, | ||
{ | ||
"_target_": "StatsHandler", | ||
"iteration_log": false | ||
} | ||
], | ||
"evaluator": { | ||
"_target_": "SupervisedEvaluator", | ||
"device": "@device", | ||
"val_data_loader": "@dataloader", | ||
"network": "@network", | ||
"inferer": "@inferer", | ||
"postprocessing": "@postprocessing", | ||
"val_handlers": "@handlers", | ||
"amp": true | ||
}, | ||
"evaluating": [ | ||
"$setattr(torch.backends.cudnn, 'benchmark', True)", | ||
"[email protected]()" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
[loggers] | ||
keys=root | ||
|
||
[handlers] | ||
keys=consoleHandler | ||
|
||
[formatters] | ||
keys=fullFormatter | ||
|
||
[logger_root] | ||
level=INFO | ||
handlers=consoleHandler | ||
|
||
[handler_consoleHandler] | ||
class=StreamHandler | ||
level=INFO | ||
formatter=fullFormatter | ||
args=(sys.stdout,) | ||
|
||
[formatter_fullFormatter] | ||
format=%(asctime)s - %(name)s - %(levelname)s - %(message)s |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
{ | ||
"schema": "https://github.com/Project-MONAI/MONAI-extra-test-data/releases/download/0.8.1/meta_schema_20220324.json", | ||
"version": "0.1.0", | ||
"changelog": { | ||
"0.1.0": "complete the model package", | ||
"0.0.1": "initialize the model package structure" | ||
}, | ||
"monai_version": "0.9.0rc1+19.g61a0dc35", | ||
"pytorch_version": "1.10.0", | ||
"numpy_version": "1.21.2", | ||
"optional_packages_version": { | ||
"nibabel": "3.2.1" | ||
}, | ||
"task": "BTCV multi-organ segmentation", | ||
"description": "A pre-trained model for volumetric (3D) multi-organ segmentation from CT image", | ||
"authors": "MONAI team", | ||
"copyright": "Copyright (c) MONAI Consortium", | ||
"data_source": "RawData.zip from https://www.synapse.org/#!Synapse:syn3193805/wiki/217752/", | ||
"data_type": "nibabel", | ||
"image_classes": "single channel data, intensity scaled to [0, 1]", | ||
"label_classes": "multi-channel data,0:background,1:spleen, 2:Right Kidney, 3:Left Kideny, 4:Gallbladder, 5:Esophagus, 6:Liver, 7:Stomach, 8:Aorta, 9:IVC, 10:Portal and Splenic Veins, 11:Pancreas, 12:Right adrenal gland, 13:Left adrenal gland", | ||
"pred_classes": "14 channels OneHot data, 0:background,1:spleen, 2:Right Kidney, 3:Left Kideny, 4:Gallbladder, 5:Esophagus, 6:Liver, 7:Stomach, 8:Aorta, 9:IVC, 10:Portal and Splenic Veins, 11:Pancreas, 12:Right adrenal gland, 13:Left adrenal gland", | ||
"eval_metrics": { | ||
"mean_dice": 0.8283 | ||
}, | ||
"intended_use": "This is an example, not to be used for diagnostic purposes", | ||
"references": [ | ||
"Hatamizadeh, Ali, et al. 'Swin UNETR: Swin Transformers for Semantic Segmentation of Brain Tumors in MRI Images. arXiv preprint arXiv:2201.01266 (2022). https://arxiv.org/abs/2201.01266.", | ||
"Tang, Yucheng, et al. 'Self-supervised pre-training of swin transformers for 3d medical image analysis. arXiv preprint arXiv:2111.14791 (2021). https://arxiv.org/abs/2111.14791." | ||
], | ||
"network_data_format": { | ||
"inputs": { | ||
"image": { | ||
"type": "image", | ||
"format": "hounsfield", | ||
"modality": "CT", | ||
"num_channels": 1, | ||
"spatial_shape": [ | ||
96, | ||
96, | ||
96 | ||
], | ||
"dtype": "float32", | ||
"value_range": [ | ||
0, | ||
1 | ||
], | ||
"is_patch_data": true, | ||
"channel_def": { | ||
"0": "image" | ||
} | ||
} | ||
}, | ||
"outputs": { | ||
"pred": { | ||
"type": "image", | ||
"format": "segmentation", | ||
"num_channels": 14, | ||
"spatial_shape": [ | ||
96, | ||
96, | ||
96 | ||
], | ||
"dtype": "float32", | ||
"value_range": [ | ||
0, | ||
1 | ||
], | ||
"is_patch_data": true, | ||
"channel_def": { | ||
"0": "background", | ||
"1": "spleen", | ||
"2": "Right Kidney", | ||
"3": "Left Kideny", | ||
"4": "Gallbladder", | ||
"5": "Esophagus", | ||
"6": "Liver", | ||
"7": "Stomach", | ||
"8": "Aorta", | ||
"9": "IVC", | ||
"10": "Portal and Splenic Veins", | ||
"11": "Pancreas", | ||
"12": "Right adrenal gland", | ||
"13": "Left adrenal gland" | ||
} | ||
} | ||
} | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
models/swin_unetr_btcv_segmentation/configs/multi_gpu_train.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
{ | ||
"device": "$torch.device(f'cuda:{dist.get_rank()}')", | ||
"network": { | ||
"_target_": "torch.nn.parallel.DistributedDataParallel", | ||
"module": "$@network_def.to(@device)", | ||
"device_ids": [ | ||
"@device" | ||
] | ||
}, | ||
"train#sampler": { | ||
"_target_": "DistributedSampler", | ||
"dataset": "@train#dataset", | ||
"even_divisible": true, | ||
"shuffle": true | ||
}, | ||
"train#dataloader#sampler": "@train#sampler", | ||
"train#dataloader#shuffle": false, | ||
"train#trainer#train_handlers": "$@train#handlers[: -2 if dist.get_rank() > 0 else None]", | ||
"validate#sampler": { | ||
"_target_": "DistributedSampler", | ||
"dataset": "@validate#dataset", | ||
"even_divisible": false, | ||
"shuffle": false | ||
}, | ||
"validate#dataloader#sampler": "@validate#sampler", | ||
"validate#evaluator#val_handlers": "$None if dist.get_rank() > 0 else @validate#handlers", | ||
"training": [ | ||
"$import torch.distributed as dist", | ||
"$dist.init_process_group(backend='nccl')", | ||
"$torch.cuda.set_device(@device)", | ||
"$monai.utils.set_determinism(seed=123)", | ||
"$setattr(torch.backends.cudnn, 'benchmark', True)", | ||
"$@train#trainer.run()", | ||
"$dist.destroy_process_group()" | ||
] | ||
} |
Oops, something went wrong.