From b8a39b2e3468eadc87afe13c487ba1ede4f6285f Mon Sep 17 00:00:00 2001 From: KumoLiu Date: Thu, 12 Oct 2023 17:56:59 +0800 Subject: [PATCH] address comments Signed-off-by: KumoLiu --- monai/bundle/scripts.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/monai/bundle/scripts.py b/monai/bundle/scripts.py index 4317001ea7..6bac1835de 100644 --- a/monai/bundle/scripts.py +++ b/monai/bundle/scripts.py @@ -1255,7 +1255,6 @@ def ckpt_export( e.g. ``--_meta#network_data_format#inputs#image#num_channels 3``. """ - bundle_root = override.pop("bundle_root", os.getcwd()) _args = update_kwargs( args=args_file, net_id=net_id, @@ -1267,7 +1266,6 @@ def ckpt_export( use_trace=use_trace, input_shape=input_shape, converter_kwargs=converter_kwargs, - bundle_root=bundle_root, **override, ) _log_input_summary(tag="ckpt_export", args=_args) @@ -1294,20 +1292,25 @@ def ckpt_export( converter_kwargs={}, ) - parser = ConfigParser() + if "bundle_root" in _args: + bundle_root = _args["bundle_root"] + else: + bundle_root = os.getcwd() + parser = ConfigParser() parser.read_config(f=config_file_) + meta_file_ = os.path.join(bundle_root, "configs", "metadata.json") if meta_file_ is None else meta_file_ + if os.path.exists(meta_file_): + parser.read_meta(f=meta_file_) + # the rest key-values in the _args are to override config content for k, v in _args.items(): parser[k] = v - meta_file_ = os.path.join(bundle_root, "configs", "metadata.json") if meta_file_ is None else meta_file_ filepath_ = os.path.join(bundle_root, "models", "model.ts") if filepath_ is None else filepath_ ckpt_file_ = os.path.join(bundle_root, "models", "model.pt") if ckpt_file_ is None else ckpt_file_ if not os.path.exists(ckpt_file_): raise FileNotFoundError(f'Checkpoint file "{ckpt_file_}" not found, please specify it in argument "ckpt_file".') - if os.path.exists(meta_file_): - parser.read_meta(f=meta_file_) net_id_ = "network_def" if net_id_ is None else net_id_ try: