From 25555f7c031d9768afd18590f8cbf3bcec5a64ea Mon Sep 17 00:00:00 2001 From: Yiheng Wang Date: Tue, 6 Feb 2024 21:37:08 +0800 Subject: [PATCH 1/2] Update spleen bundle Signed-off-by: Yiheng Wang --- .../configs/inference.json | 27 ++++++++++++------- .../configs/inference_trt.json | 6 +++-- .../configs/metadata.json | 3 ++- 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/models/spleen_ct_segmentation/configs/inference.json b/models/spleen_ct_segmentation/configs/inference.json index e82996d2..97b77f20 100644 --- a/models/spleen_ct_segmentation/configs/inference.json +++ b/models/spleen_ct_segmentation/configs/inference.json @@ -5,6 +5,10 @@ ], "bundle_root": ".", "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')", @@ -117,18 +121,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 @@ -144,8 +145,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()" diff --git a/models/spleen_ct_segmentation/configs/inference_trt.json b/models/spleen_ct_segmentation/configs/inference_trt.json index adfbca41..ec1e88ab 100644 --- a/models/spleen_ct_segmentation/configs/inference_trt.json +++ b/models/spleen_ct_segmentation/configs/inference_trt.json @@ -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)" + ] } diff --git a/models/spleen_ct_segmentation/configs/metadata.json b/models/spleen_ct_segmentation/configs/metadata.json index 2cea6a99..50cb819b 100644 --- a/models/spleen_ct_segmentation/configs/metadata.json +++ b/models/spleen_ct_segmentation/configs/metadata.json @@ -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", From 824e5f6c7feabdc9aa440b7eb4469c2a6dab7dc7 Mon Sep 17 00:00:00 2001 From: Yiheng Wang Date: Tue, 6 Feb 2024 21:56:22 +0800 Subject: [PATCH 2/2] update test file Signed-off-by: Yiheng Wang --- ci/unit_tests/test_spleen_ct_segmentation.py | 17 ++++++++++++++++- .../configs/inference.json | 16 +++++++++------- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/ci/unit_tests/test_spleen_ct_segmentation.py b/ci/unit_tests/test_spleen_ct_segmentation.py index 8db1f761..d9dacf87 100644 --- a/ci/unit_tests/test_spleen_ct_segmentation.py +++ b/ci/unit_tests/test_spleen_ct_segmentation.py @@ -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() @@ -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) diff --git a/models/spleen_ct_segmentation/configs/inference.json b/models/spleen_ct_segmentation/configs/inference.json index 97b77f20..4ee2705f 100644 --- a/models/spleen_ct_segmentation/configs/inference.json +++ b/models/spleen_ct_segmentation/configs/inference.json @@ -1,9 +1,11 @@ { "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", @@ -39,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, @@ -62,7 +64,7 @@ }, { "_target_": "ScaleIntensityRanged", - "keys": "image", + "keys": "@image_key", "a_min": -57, "a_max": 164, "b_min": 0, @@ -71,7 +73,7 @@ }, { "_target_": "EnsureTyped", - "keys": "image" + "keys": "@image_key" } ] }, @@ -109,7 +111,7 @@ "_target_": "Invertd", "keys": "pred", "transform": "@preprocessing", - "orig_keys": "image", + "orig_keys": "@image_key", "nearest_interp": false, "to_tensor": true },