MCPcopy Create free account
hub / github.com/Project-MONAI/MONAI / __init__

Method __init__

monai/bundle/workflows.py:64–137  ·  view source on GitHub ↗
(
        self,
        workflow_type: str | None = None,
        properties_path: PathLike | None = None,
        meta_file: str | Sequence[str] | None = None,
        logging_file: str | None = None,
    )

Source from the content-addressed store, hash-verified

62 supported_infer_type: tuple = ("infer", "inference", "eval", "evaluation")
63
64 def __init__(
65 self,
66 workflow_type: str | None = None,
67 properties_path: PathLike | None = None,
68 meta_file: str | Sequence[str] | None = None,
69 logging_file: str | None = None,
70 ):
71 if logging_file is not None:
72 if not os.path.isfile(logging_file):
73 raise FileNotFoundError(f"Cannot find the logging config file: {logging_file}.")
74 logger.info(f"Setting logging properties based on config: {logging_file}.")
75 fileConfig(logging_file, disable_existing_loggers=False)
76
77 if meta_file is not None:
78 if isinstance(meta_file, str) and not os.path.isfile(meta_file):
79 logger.error(
80 f"Cannot find the metadata config file: {meta_file}. "
81 "Please see: https://monai.readthedocs.io/en/stable/mb_specification.html"
82 )
83 meta_file = None
84 if isinstance(meta_file, list):
85 for f in meta_file:
86 if not os.path.isfile(f):
87 logger.error(
88 f"Cannot find the metadata config file: {f}. "
89 "Please see: https://monai.readthedocs.io/en/stable/mb_specification.html"
90 )
91 meta_file = None
92
93 if workflow_type is not None:
94 if workflow_type.lower() in self.supported_train_type:
95 workflow_type = "train"
96 elif workflow_type.lower() in self.supported_infer_type:
97 workflow_type = "infer"
98 else:
99 raise ValueError(f"Unsupported workflow type: '{workflow_type}'.")
100
101 if properties_path is not None:
102 properties_path = Path(properties_path)
103 if not properties_path.is_file():
104 raise ValueError(f"Property file {properties_path} does not exist.")
105 with open(properties_path) as json_file:
106 try:
107 properties = json.load(json_file)
108 self.properties: dict = {}
109 if workflow_type is not None and workflow_type in properties:
110 self.properties = properties[workflow_type]
111 if "meta" in properties:
112 self.properties.update(properties["meta"])
113 elif workflow_type is None:
114 if "meta" in properties:
115 self.properties = properties["meta"]
116 logger.info(
117 "No workflow type specified, default to load meta properties from property file."
118 )
119 else:
120 logger.warning("No 'meta' key found in properties while workflow_type is None.")
121 except KeyError as e:

Callers 2

__init__Method · 0.45
__init__Method · 0.45

Calls 3

infoMethod · 0.80
loadMethod · 0.80
updateMethod · 0.45

Tested by

no test coverage detected