Skip to content
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

Update spleen bundle to support checkpoint loader #554

Merged
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
17 changes: 16 additions & 1 deletion ci/unit_tests/test_spleen_ct_segmentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,19 @@
]


def test_order(test_name1, test_name2):
def get_order(name):
if "train" in name:
return 1
if "eval" in name:
return 2
if "infer" in name:
return 3
return 4

return get_order(test_name1) - get_order(test_name2)


class TestSpleenCTSeg(unittest.TestCase):
def setUp(self):
self.dataset_dir = tempfile.mkdtemp()
Expand Down Expand Up @@ -102,4 +115,6 @@ def test_infer_config(self, override):


if __name__ == "__main__":
unittest.main()
loader = unittest.TestLoader()
loader.sortTestMethodsUsing = test_order
unittest.main(testLoader=loader)
43 changes: 27 additions & 16 deletions models/spleen_ct_segmentation/configs/inference.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
{
"imports": [
"$import glob",
"$import numpy",
"$import os"
],
"bundle_root": ".",
"image_key": "image",
"output_dir": "$@bundle_root + '/eval'",
"output_ext": ".nii.gz",
"output_dtype": "$numpy.float32",
"output_postfix": "trans",
"separate_folder": true,
"dataset_dir": "/workspace/data/Task09_Spleen",
"datalist": "$list(sorted(glob.glob(@dataset_dir + '/imagesTs/*.nii.gz')))",
"device": "$torch.device('cuda:0' if torch.cuda.is_available() else 'cpu')",
Expand Down Expand Up @@ -35,20 +41,20 @@
"transforms": [
{
"_target_": "LoadImaged",
"keys": "image"
"keys": "@image_key"
},
{
"_target_": "EnsureChannelFirstd",
"keys": "image"
"keys": "@image_key"
},
{
"_target_": "Orientationd",
"keys": "image",
"keys": "@image_key",
"axcodes": "RAS"
},
{
"_target_": "Spacingd",
"keys": "image",
"keys": "@image_key",
"pixdim": [
1.5,
1.5,
Expand All @@ -58,7 +64,7 @@
},
{
"_target_": "ScaleIntensityRanged",
"keys": "image",
"keys": "@image_key",
"a_min": -57,
"a_max": 164,
"b_min": 0,
Expand All @@ -67,7 +73,7 @@
},
{
"_target_": "EnsureTyped",
"keys": "image"
"keys": "@image_key"
}
]
},
Expand Down Expand Up @@ -105,7 +111,7 @@
"_target_": "Invertd",
"keys": "pred",
"transform": "@preprocessing",
"orig_keys": "image",
"orig_keys": "@image_key",
"nearest_interp": false,
"to_tensor": true
},
Expand All @@ -117,18 +123,15 @@
{
"_target_": "SaveImaged",
"keys": "pred",
"output_dir": "@output_dir"
"output_dir": "@output_dir",
"output_ext": "@output_ext",
"output_dtype": "@output_dtype",
"output_postfix": "@output_postfix",
"separate_folder": "@separate_folder"
}
]
},
"handlers": [
{
"_target_": "CheckpointLoader",
"load_path": "$@bundle_root + '/models/model.pt'",
"load_dict": {
"model": "@network"
}
},
{
"_target_": "StatsHandler",
"iteration_log": false
Expand All @@ -144,8 +147,16 @@
"val_handlers": "@handlers",
"amp": true
},
"checkpointloader": {
"_target_": "CheckpointLoader",
"load_path": "$@bundle_root + '/models/model.pt'",
"load_dict": {
"model": "@network"
}
},
"initialize": [
"$monai.utils.set_determinism(seed=123)"
"$monai.utils.set_determinism(seed=123)",
"$@checkpointloader(@evaluator)"
],
"run": [
"$@evaluator.run()"
Expand Down
6 changes: 4 additions & 2 deletions models/spleen_ct_segmentation/configs/inference_trt.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
"$import os",
"$import torch_tensorrt"
],
"handlers#0#_disabled_": true,
"network_def": "$torch.jit.load(@bundle_root + '/models/model_trt.ts')",
"evaluator#amp": false
"evaluator#amp": false,
"initialize": [
"$monai.utils.set_determinism(seed=123)"
]
}
3 changes: 2 additions & 1 deletion models/spleen_ct_segmentation/configs/metadata.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"schema": "https://github.com/Project-MONAI/MONAI-extra-test-data/releases/download/0.8.1/meta_schema_20220324.json",
"version": "0.5.4",
"version": "0.5.5",
"changelog": {
"0.5.5": "add checkpoint loader for infer",
"0.5.4": "update to use monai 1.3.0",
"0.5.3": "fix the wrong GPU index issue of multi-node",
"0.5.2": "remove error dollar symbol in readme",
Expand Down
Loading