From 4c0f382c1beb4331143d9a173ffe5851533b67b7 Mon Sep 17 00:00:00 2001 From: KumoLiu Date: Thu, 23 Nov 2023 17:49:14 +0800 Subject: [PATCH 01/10] fix #6959 Signed-off-by: KumoLiu --- docs/source/mb_specification.rst | 4 ++-- monai/bundle/utils.py | 2 +- tests/testing_data/metadata.json | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/source/mb_specification.rst b/docs/source/mb_specification.rst index cedafa0d23..390c9fe828 100644 --- a/docs/source/mb_specification.rst +++ b/docs/source/mb_specification.rst @@ -63,7 +63,7 @@ This file contains the metadata information relating to the model, including wha * **monai_version**: version of MONAI the bundle was generated on, later versions expected to work. * **pytorch_version**: version of Pytorch the bundle was generated on, later versions expected to work. * **numpy_version**: version of Numpy the bundle was generated on, later versions expected to work. -* **optional_packages_version**: dictionary relating optional package names to their versions, these packages are not needed but are recommended to be installed with this stated minimum version. +* **required_packages_version**: dictionary relating required package names to their versions, these packages are needed to be installed with this stated minimum version. * **task**: plain-language description of what the model is meant to do. * **description**: longer form plain-language description of what the model is, what it does, etc. * **authors**: state author(s) of the model. @@ -124,7 +124,7 @@ An example JSON metadata file: "monai_version": "0.9.0", "pytorch_version": "1.10.0", "numpy_version": "1.21.2", - "optional_packages_version": {"nibabel": "3.2.1"}, + "required_packages_version": {"nibabel": "3.2.1"}, "task": "Decathlon spleen segmentation", "description": "A pre-trained model for volumetric (3D) segmentation of the spleen from CT image", "authors": "MONAI team", diff --git a/monai/bundle/utils.py b/monai/bundle/utils.py index b187159c89..f79f3c3ef5 100644 --- a/monai/bundle/utils.py +++ b/monai/bundle/utils.py @@ -36,7 +36,7 @@ "monai_version": _conf_values["MONAI"], "pytorch_version": str(_conf_values["Pytorch"]).split("+")[0].split("a")[0], # 1.9.0a0+df837d0 or 1.13.0+cu117 "numpy_version": _conf_values["Numpy"], - "optional_packages_version": {}, + "required_packages_version": {}, "task": "Describe what the network predicts", "description": "A longer description of what the network does, use context, inputs, outputs, etc.", "authors": "Your Name Here", diff --git a/tests/testing_data/metadata.json b/tests/testing_data/metadata.json index 98a17b73c5..938338f9dd 100644 --- a/tests/testing_data/metadata.json +++ b/tests/testing_data/metadata.json @@ -8,7 +8,7 @@ "monai_version": "0.9.0", "pytorch_version": "1.10.0", "numpy_version": "1.21.2", - "optional_packages_version": { + "required_packages_version": { "nibabel": "3.2.1" }, "task": "Decathlon spleen segmentation", From 724e09662821440e37813783073ee987c429f17c Mon Sep 17 00:00:00 2001 From: KumoLiu Date: Mon, 27 Nov 2023 16:45:49 +0800 Subject: [PATCH 02/10] address comments Signed-off-by: KumoLiu --- monai/bundle/config_parser.py | 4 ++-- monai/bundle/reference_resolver.py | 16 +++++++++++++++- monai/bundle/utils.py | 3 +++ 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/monai/bundle/config_parser.py b/monai/bundle/config_parser.py index 829036af6f..a2ffeedc92 100644 --- a/monai/bundle/config_parser.py +++ b/monai/bundle/config_parser.py @@ -118,7 +118,7 @@ def __init__( self.ref_resolver = ReferenceResolver() if config is None: config = {self.meta_key: {}} - self.set(config=config) + self.set(config=self.ref_resolver.normalize_meta_id(config)) def __repr__(self): return f"{self.config}" @@ -221,7 +221,7 @@ def set(self, config: Any, id: str = "", recursive: bool = True) -> None: if isinstance(conf_, dict) and k not in conf_: conf_[k] = {} conf_ = conf_[k if isinstance(conf_, dict) else int(k)] - self[ReferenceResolver.normalize_id(id)] = config + self[ReferenceResolver.normalize_id(id)] = self.ref_resolver.normalize_meta_id(config) def update(self, pairs: dict[str, Any]) -> None: """ diff --git a/monai/bundle/reference_resolver.py b/monai/bundle/reference_resolver.py index b36f2cc4a5..cad5313513 100644 --- a/monai/bundle/reference_resolver.py +++ b/monai/bundle/reference_resolver.py @@ -17,7 +17,7 @@ from typing import Any, Iterator from monai.bundle.config_item import ConfigComponent, ConfigExpression, ConfigItem -from monai.bundle.utils import ID_REF_KEY, ID_SEP_KEY +from monai.bundle.utils import ID_REF_KEY, ID_SEP_KEY, DEPRECATED_ID_MAPPING from monai.utils import allow_missing_reference, look_up_option __all__ = ["ReferenceResolver"] @@ -202,6 +202,20 @@ def normalize_id(cls, id: str | int) -> str: """ return str(id).replace("#", cls.sep) # backward compatibility `#` is the old separator + @classmethod + def normalize_meta_id(cls, config: Any) -> str: + """ + Update deprecated id use `DEPRECATED_ID_MAPPING`. + + Args: + config: input config to be updated. + """ + for _id, _new_id in DEPRECATED_ID_MAPPING.items(): + if _id in config.keys(): + warnings.warn(f"Detect deprecated id: {_id} in config, replacing with {_new_id}.") + config[_new_id] = config.pop(_id) + return config + @classmethod def split_id(cls, id: str | int, last: bool = False) -> list[str]: """ diff --git a/monai/bundle/utils.py b/monai/bundle/utils.py index f79f3c3ef5..fd1c0f5299 100644 --- a/monai/bundle/utils.py +++ b/monai/bundle/utils.py @@ -157,6 +157,9 @@ DEFAULT_EXP_MGMT_SETTINGS = {"mlflow": DEFAULT_MLFLOW_SETTINGS} # default experiment management settings +DEPRECATED_ID_MAPPING = { + "optional_packages_version": "required_packages_version" +} def load_bundle_config(bundle_path: str, *config_names: str, **load_kw_args: Any) -> Any: """ From 5587ee34bac92e10e37fc84e33448efeb3aa4b54 Mon Sep 17 00:00:00 2001 From: KumoLiu Date: Mon, 27 Nov 2023 16:53:16 +0800 Subject: [PATCH 03/10] fix format Signed-off-by: KumoLiu --- monai/bundle/reference_resolver.py | 4 ++-- monai/bundle/utils.py | 5 ++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/monai/bundle/reference_resolver.py b/monai/bundle/reference_resolver.py index cad5313513..4e6cffb867 100644 --- a/monai/bundle/reference_resolver.py +++ b/monai/bundle/reference_resolver.py @@ -17,7 +17,7 @@ from typing import Any, Iterator from monai.bundle.config_item import ConfigComponent, ConfigExpression, ConfigItem -from monai.bundle.utils import ID_REF_KEY, ID_SEP_KEY, DEPRECATED_ID_MAPPING +from monai.bundle.utils import DEPRECATED_ID_MAPPING, ID_REF_KEY, ID_SEP_KEY from monai.utils import allow_missing_reference, look_up_option __all__ = ["ReferenceResolver"] @@ -203,7 +203,7 @@ def normalize_id(cls, id: str | int) -> str: return str(id).replace("#", cls.sep) # backward compatibility `#` is the old separator @classmethod - def normalize_meta_id(cls, config: Any) -> str: + def normalize_meta_id(cls, config: Any) -> Any: """ Update deprecated id use `DEPRECATED_ID_MAPPING`. diff --git a/monai/bundle/utils.py b/monai/bundle/utils.py index fd1c0f5299..292025b643 100644 --- a/monai/bundle/utils.py +++ b/monai/bundle/utils.py @@ -157,9 +157,8 @@ DEFAULT_EXP_MGMT_SETTINGS = {"mlflow": DEFAULT_MLFLOW_SETTINGS} # default experiment management settings -DEPRECATED_ID_MAPPING = { - "optional_packages_version": "required_packages_version" -} +DEPRECATED_ID_MAPPING = {"optional_packages_version": "required_packages_version"} + def load_bundle_config(bundle_path: str, *config_names: str, **load_kw_args: Any) -> Any: """ From ec231c8d3d52510f54d08d3cee15e0639fe11264 Mon Sep 17 00:00:00 2001 From: KumoLiu Date: Mon, 27 Nov 2023 17:13:56 +0800 Subject: [PATCH 04/10] fix ci Signed-off-by: KumoLiu --- monai/bundle/reference_resolver.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/monai/bundle/reference_resolver.py b/monai/bundle/reference_resolver.py index 4e6cffb867..c89c2e26e9 100644 --- a/monai/bundle/reference_resolver.py +++ b/monai/bundle/reference_resolver.py @@ -210,10 +210,11 @@ def normalize_meta_id(cls, config: Any) -> Any: Args: config: input config to be updated. """ - for _id, _new_id in DEPRECATED_ID_MAPPING.items(): - if _id in config.keys(): - warnings.warn(f"Detect deprecated id: {_id} in config, replacing with {_new_id}.") - config[_new_id] = config.pop(_id) + if isinstance(config, dict): + for _id, _new_id in DEPRECATED_ID_MAPPING.items(): + if _id in config.keys(): + warnings.warn(f"Detect deprecated id: {_id} in config, replacing with {_new_id}.") + config[_new_id] = config.pop(_id) return config @classmethod From d3b907171dd685112d75c0846ad60807f2211123 Mon Sep 17 00:00:00 2001 From: YunLiu <55491388+KumoLiu@users.noreply.github.com> Date: Wed, 29 Nov 2023 09:51:19 +0800 Subject: [PATCH 05/10] Update monai/bundle/reference_resolver.py Co-authored-by: Eric Kerfoot <17726042+ericspod@users.noreply.github.com> Signed-off-by: YunLiu <55491388+KumoLiu@users.noreply.github.com> --- monai/bundle/reference_resolver.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/monai/bundle/reference_resolver.py b/monai/bundle/reference_resolver.py index c89c2e26e9..720255b7a4 100644 --- a/monai/bundle/reference_resolver.py +++ b/monai/bundle/reference_resolver.py @@ -213,7 +213,7 @@ def normalize_meta_id(cls, config: Any) -> Any: if isinstance(config, dict): for _id, _new_id in DEPRECATED_ID_MAPPING.items(): if _id in config.keys(): - warnings.warn(f"Detect deprecated id: {_id} in config, replacing with {_new_id}.") + warnings.warn(f"Detected deprecated name '{_id}' in configuration file, replacing with '{_new_id}'.") config[_new_id] = config.pop(_id) return config From e916f8e63bfe212d58f3c60c5269058bc479a020 Mon Sep 17 00:00:00 2001 From: YunLiu <55491388+KumoLiu@users.noreply.github.com> Date: Wed, 29 Nov 2023 09:59:08 +0800 Subject: [PATCH 06/10] Update monai/bundle/reference_resolver.py Co-authored-by: Eric Kerfoot <17726042+ericspod@users.noreply.github.com> Signed-off-by: YunLiu <55491388+KumoLiu@users.noreply.github.com> --- monai/bundle/reference_resolver.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/monai/bundle/reference_resolver.py b/monai/bundle/reference_resolver.py index 720255b7a4..87067e59e6 100644 --- a/monai/bundle/reference_resolver.py +++ b/monai/bundle/reference_resolver.py @@ -202,10 +202,9 @@ def normalize_id(cls, id: str | int) -> str: """ return str(id).replace("#", cls.sep) # backward compatibility `#` is the old separator - @classmethod - def normalize_meta_id(cls, config: Any) -> Any: + def normalize_meta_id(self, config: Any) -> Any: """ - Update deprecated id use `DEPRECATED_ID_MAPPING`. + Update deprecated identifiers in `config` using `DEPRECATED_ID_MAPPING`. This will replace names that are marked as deprecated with their replacement. Args: config: input config to be updated. From a9bb50b0542c217749243ac6b12b9cfa2ae90479 Mon Sep 17 00:00:00 2001 From: KumoLiu Date: Wed, 29 Nov 2023 10:01:08 +0800 Subject: [PATCH 07/10] fix ci Signed-off-by: KumoLiu --- monai/bundle/reference_resolver.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/monai/bundle/reference_resolver.py b/monai/bundle/reference_resolver.py index 87067e59e6..044b9b879e 100644 --- a/monai/bundle/reference_resolver.py +++ b/monai/bundle/reference_resolver.py @@ -204,7 +204,8 @@ def normalize_id(cls, id: str | int) -> str: def normalize_meta_id(self, config: Any) -> Any: """ - Update deprecated identifiers in `config` using `DEPRECATED_ID_MAPPING`. This will replace names that are marked as deprecated with their replacement. + Update deprecated identifiers in `config` using `DEPRECATED_ID_MAPPING`. + This will replace names that are marked as deprecated with their replacement. Args: config: input config to be updated. From d92b196cb6cab586208fe794d1c75cb3e0a1d126 Mon Sep 17 00:00:00 2001 From: YunLiu <55491388+KumoLiu@users.noreply.github.com> Date: Wed, 24 Jul 2024 17:32:02 +0800 Subject: [PATCH 08/10] fix format Signed-off-by: YunLiu <55491388+KumoLiu@users.noreply.github.com> --- monai/bundle/reference_resolver.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/monai/bundle/reference_resolver.py b/monai/bundle/reference_resolver.py index 044b9b879e..050cd75fa7 100644 --- a/monai/bundle/reference_resolver.py +++ b/monai/bundle/reference_resolver.py @@ -213,7 +213,9 @@ def normalize_meta_id(self, config: Any) -> Any: if isinstance(config, dict): for _id, _new_id in DEPRECATED_ID_MAPPING.items(): if _id in config.keys(): - warnings.warn(f"Detected deprecated name '{_id}' in configuration file, replacing with '{_new_id}'.") + warnings.warn( + f"Detected deprecated name '{_id}' in configuration file, replacing with '{_new_id}'." + ) config[_new_id] = config.pop(_id) return config From 612984aae242064bcd384409978609130ce209de Mon Sep 17 00:00:00 2001 From: YunLiu <55491388+KumoLiu@users.noreply.github.com> Date: Fri, 26 Jul 2024 15:59:22 +0800 Subject: [PATCH 09/10] update schema Signed-off-by: YunLiu <55491388+KumoLiu@users.noreply.github.com> --- tests/testing_data/metadata.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testing_data/metadata.json b/tests/testing_data/metadata.json index 938338f9dd..29737e3a9d 100644 --- a/tests/testing_data/metadata.json +++ b/tests/testing_data/metadata.json @@ -1,5 +1,5 @@ { - "schema": "https://github.com/Project-MONAI/MONAI-extra-test-data/releases/download/0.8.1/meta_schema_20220324.json", + "schema": "https://github.com/Project-MONAI/MONAI-extra-test-data/releases/download/0.8.1/meta_schema_20240725.json", "version": "0.1.0", "changelog": { "0.1.0": "complete the model package", From c7551d18463eeac0c1cbeafa5d31bb39ed0c3006 Mon Sep 17 00:00:00 2001 From: YunLiu <55491388+KumoLiu@users.noreply.github.com> Date: Fri, 26 Jul 2024 17:35:18 +0800 Subject: [PATCH 10/10] update test data Signed-off-by: YunLiu <55491388+KumoLiu@users.noreply.github.com> --- tests/testing_data/data_config.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/testing_data/data_config.json b/tests/testing_data/data_config.json index 8b1d2868b7..79033dd0d6 100644 --- a/tests/testing_data/data_config.json +++ b/tests/testing_data/data_config.json @@ -162,9 +162,9 @@ }, "configs": { "test_meta_file": { - "url": "https://github.com/Project-MONAI/MONAI-extra-test-data/releases/download/0.8.1/meta_schema_20220324.json", + "url": "https://github.com/Project-MONAI/MONAI-extra-test-data/releases/download/0.8.1/meta_schema_20240725.json", "hash_type": "md5", - "hash_val": "662135097106b71067cd1fc657f8720f" + "hash_val": "06954cad2cc5d3784e72077ac76f0fc8" } } }