Skip to content

Add DeepEdit Bundle #694

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
146 changes: 146 additions & 0 deletions deepedit/deepedit_bundle/configs/inference.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
{
"imports": [
"$import glob",
"$import os",
"$import ignite"
],
"bundle_root": "/workspace/tutorials/deepedit/deepedit_bundle",
"output_dir": "$@bundle_root + '/eval'",
"dataset_dir": "/workspace/Datasets/MSD_datasets/Task09_Spleen",
"datalist": "$list(sorted(glob.glob(@dataset_dir + '/imagesTs/*.nii.gz')))",
"label_names": {"spleen": 1, "background": 0},
"spatial_size": [128, 128, 128],
"number_intensity_ch": 1,
"device": "$torch.device('cuda:0' if torch.cuda.is_available() else 'cpu')",
"network_def": {
"_target_": "DynUNet",
"spatial_dims": 3,
"in_channels": "$len(@label_names) + @number_intensity_ch",
"out_channels": "$len(@label_names)",
"kernel_size": [3, 3, 3, 3, 3, 3],
"strides": [1, 2, 2, 2, 2, [2, 2, 1]],
"upsample_kernel_size": [2, 2, 2, 2, [2, 2, 1]],
"norm_name": "instance",
"deep_supervision": false,
"res_block": true
},
"network": "$@network_def.to(@device)",
"pre_transforms": {
"_target_": "Compose",
"transforms": [
{
"_target_": "LoadImaged",
"keys": "image",
"reader": "ITKReader"
},
{
"_target_": "EnsureChannelFirstd",
"keys": "image"
},
{
"_target_": "Orientationd",
"keys": "image",
"axcodes": "RAS"
},
{
"_target_": "ScaleIntensityRanged",
"keys": "image",
"a_min":-175,
"a_max": 250,
"b_min": 0.0,
"b_max": 1.0,
"clip": true
},
{
"_target_": "Resized",
"keys": "image",
"spatial_size": "@spatial_size",
"mode": "area"
},
{
"_target_": "DiscardAddGuidanced",
"keys": "image",
"label_names": "@label_names",
"number_intensity_ch": "@number_intensity_ch"
},
{
"_target_": "EnsureTyped",
"keys": "image"
}
]
},
"dataset": {
"_target_": "Dataset",
"data": "$[{'image': i} for i in @datalist]",
"transform": "@pre_transforms"
},
"dataloader": {
"_target_": "DataLoader",
"dataset": "@dataset",
"batch_size": 1,
"shuffle": false,
"num_workers": 2
},
"inferer": {
"_target_": "SimpleInferer"
},
"post_transforms": {
"_target_": "Compose",
"transforms": [
{
"_target_": "EnsureTyped",
"keys": "pred"
},
{
"_target_": "Activationsd",
"keys": "pred",
"softmax": true
},
{
"_target_": "Invertd",
"keys": "pred",
"transform": "@pre_transforms",
"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": "@post_transforms",
"val_handlers": "@handlers",
"amp": true
},
"evaluating": [
"$setattr(torch.backends.cudnn, 'benchmark', True)",
"[email protected]()"
]
}
21 changes: 21 additions & 0 deletions deepedit/deepedit_bundle/configs/logging.conf
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
75 changes: 75 additions & 0 deletions deepedit/deepedit_bundle/configs/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
{
"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.0",
"pytorch_version": "1.10.0",
"numpy_version": "1.21.2",
"optional_packages_version": {
"nibabel": "3.2.1"
},
"task": "Decathlon spleen segmentation",
"description": "This is a pre-trained model for 3D segmentation of the spleen organ from CT images using DeepEdit.",
"authors": "MONAI team",
"copyright": "Copyright (c) MONAI Consortium",
"data_source": "Task09_Spleen.tar from http://medicaldecathlon.com/",
"data_type": "dicom",
"image_classes": "single channel data, intensity scaled to [0, 1]",
"label_classes": "single channel data, 1 is spleen, 0 is background",
"pred_classes": "2 channels OneHot data, channel 1 is spleen, channel 0 is background",
"eval_metrics": {
"mean_dice": 0.92
},
"intended_use": "This is an example, not to be used for diagnostic purposes",
"references": [
"Sakinis, Tomas, et al. 'Interactive segmentation of medical images through fully convolutional neural networks.' arXiv preprint arXiv:1903.08205 (2019)"
],
"network_data_format": {
"inputs": {
"image": {
"type": "image",
"format": "magnitude",
"num_channels": 3,
"spatial_shape": [
128,
128,
128
],
"dtype": "float32",
"value_range": [
0,
1
],
"is_patch_data": false,
"channel_def": {
"0": "image"
}
}
},
"outputs": {
"pred": {
"type": "image",
"format": "segmentation",
"num_channels": 2,
"spatial_shape": [
128,
128,
128
],
"dtype": "float32",
"value_range": [
0,
1
],
"is_patch_data": false,
"channel_def": {
"0": "background",
"1": "spleen"
}
}
}
}
}
34 changes: 34 additions & 0 deletions deepedit/deepedit_bundle/configs/multi_gpu_train.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"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()"
]
}
Loading