|
| 1 | +# Copyright (c) MONAI Consortium |
| 2 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 3 | +# you may not use this file except in compliance with the License. |
| 4 | +# You may obtain a copy of the License at |
| 5 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 6 | +# Unless required by applicable law or agreed to in writing, software |
| 7 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 8 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 9 | +# See the License for the specific language governing permissions and |
| 10 | +# limitations under the License. |
| 11 | + |
| 12 | +""" |
| 13 | +The predefined properties for a bundle workflow, other applications can leverage the properties |
| 14 | +to interact with the bundle workflow. |
| 15 | +Some properties are required and some are optional, optional properties mean: if some component of the |
| 16 | +bundle workflow refer to the property, the property must be defined, otherwise, the property can be None. |
| 17 | +Every item in this `TrainProperties` or `InferProperties` dictionary is a property, |
| 18 | +the key is the property name and the values include: |
| 19 | +1. description. |
| 20 | +2. whether it's a required property. |
| 21 | +3. config item ID name (only applicable when the bundle workflow is defined in config). |
| 22 | +4. reference config item ID name (only applicable when the bundle workflow is defined in config). |
| 23 | +
|
| 24 | +""" |
| 25 | + |
| 26 | +from __future__ import annotations |
| 27 | + |
| 28 | +from monai.bundle.utils import ID_SEP_KEY |
| 29 | +from monai.utils import BundleProperty, BundlePropertyConfig |
| 30 | + |
| 31 | +TrainProperties = { |
| 32 | + "bundle_root": { |
| 33 | + BundleProperty.DESC: "root path of the bundle.", |
| 34 | + BundleProperty.REQUIRED: True, |
| 35 | + BundlePropertyConfig.ID: "bundle_root", |
| 36 | + }, |
| 37 | + "device": { |
| 38 | + BundleProperty.DESC: "target device to execute the bundle workflow.", |
| 39 | + BundleProperty.REQUIRED: True, |
| 40 | + BundlePropertyConfig.ID: "device", |
| 41 | + }, |
| 42 | + "dataset_dir": { |
| 43 | + BundleProperty.DESC: "directory path of the dataset.", |
| 44 | + BundleProperty.REQUIRED: True, |
| 45 | + BundlePropertyConfig.ID: "dataset_dir", |
| 46 | + }, |
| 47 | + "trainer": { |
| 48 | + BundleProperty.DESC: "training workflow engine.", |
| 49 | + BundleProperty.REQUIRED: True, |
| 50 | + BundlePropertyConfig.ID: f"train{ID_SEP_KEY}trainer", |
| 51 | + }, |
| 52 | + "max_epochs": { |
| 53 | + BundleProperty.DESC: "max number of epochs to execute the training.", |
| 54 | + BundleProperty.REQUIRED: True, |
| 55 | + BundlePropertyConfig.ID: f"train{ID_SEP_KEY}trainer{ID_SEP_KEY}max_epochs", |
| 56 | + }, |
| 57 | + "train_dataset": { |
| 58 | + BundleProperty.DESC: "PyTorch dataset object for the training logic.", |
| 59 | + BundleProperty.REQUIRED: True, |
| 60 | + BundlePropertyConfig.ID: f"train{ID_SEP_KEY}dataset", |
| 61 | + }, |
| 62 | + "train_dataset_data": { |
| 63 | + BundleProperty.DESC: "data source for the training dataset.", |
| 64 | + BundleProperty.REQUIRED: True, |
| 65 | + BundlePropertyConfig.ID: f"train{ID_SEP_KEY}dataset{ID_SEP_KEY}data", |
| 66 | + }, |
| 67 | + "train_inferer": { |
| 68 | + BundleProperty.DESC: "MONAI Inferer object to execute the model computation in training.", |
| 69 | + BundleProperty.REQUIRED: True, |
| 70 | + BundlePropertyConfig.ID: f"train{ID_SEP_KEY}inferer", |
| 71 | + }, |
| 72 | + "train_handlers": { |
| 73 | + BundleProperty.DESC: "event-handlers for the training logic.", |
| 74 | + BundleProperty.REQUIRED: False, |
| 75 | + BundlePropertyConfig.ID: f"train{ID_SEP_KEY}handlers", |
| 76 | + BundlePropertyConfig.REF_ID: f"train{ID_SEP_KEY}trainer{ID_SEP_KEY}train_handlers", |
| 77 | + }, |
| 78 | + "train_preprocessing": { |
| 79 | + BundleProperty.DESC: "preprocessing for the training input data.", |
| 80 | + BundleProperty.REQUIRED: False, |
| 81 | + BundlePropertyConfig.ID: f"train{ID_SEP_KEY}preprocessing", |
| 82 | + BundlePropertyConfig.REF_ID: f"train{ID_SEP_KEY}dataset{ID_SEP_KEY}transform", |
| 83 | + }, |
| 84 | + "train_postprocessing": { |
| 85 | + BundleProperty.DESC: "postprocessing for the training model output data.", |
| 86 | + BundleProperty.REQUIRED: False, |
| 87 | + BundlePropertyConfig.ID: f"train{ID_SEP_KEY}postprocessing", |
| 88 | + BundlePropertyConfig.REF_ID: f"train{ID_SEP_KEY}trainer{ID_SEP_KEY}postprocessing", |
| 89 | + }, |
| 90 | + "train_key_metric": { |
| 91 | + BundleProperty.DESC: "key metric to compute on the training data.", |
| 92 | + BundleProperty.REQUIRED: False, |
| 93 | + BundlePropertyConfig.ID: f"train{ID_SEP_KEY}key_metric", |
| 94 | + BundlePropertyConfig.REF_ID: f"train{ID_SEP_KEY}trainer{ID_SEP_KEY}key_train_metric", |
| 95 | + }, |
| 96 | + "evaluator": { |
| 97 | + BundleProperty.DESC: "validation workflow engine.", |
| 98 | + BundleProperty.REQUIRED: False, |
| 99 | + BundlePropertyConfig.ID: f"validate{ID_SEP_KEY}evaluator", |
| 100 | + BundlePropertyConfig.REF_ID: "validator", # this REF_ID is the arg name of `ValidationHandler` |
| 101 | + }, |
| 102 | + "val_interval": { |
| 103 | + BundleProperty.DESC: "validation interval during the training.", |
| 104 | + BundleProperty.REQUIRED: False, |
| 105 | + BundlePropertyConfig.ID: "val_interval", |
| 106 | + BundlePropertyConfig.REF_ID: "interval", # this REF_ID is the arg name of `ValidationHandler` |
| 107 | + }, |
| 108 | + "val_handlers": { |
| 109 | + BundleProperty.DESC: "event-handlers for the validation logic.", |
| 110 | + BundleProperty.REQUIRED: False, |
| 111 | + BundlePropertyConfig.ID: f"validate{ID_SEP_KEY}handlers", |
| 112 | + BundlePropertyConfig.REF_ID: f"validate{ID_SEP_KEY}evaluator{ID_SEP_KEY}val_handlers", |
| 113 | + }, |
| 114 | + "val_dataset": { |
| 115 | + BundleProperty.DESC: "PyTorch dataset object for the validation logic.", |
| 116 | + BundleProperty.REQUIRED: False, |
| 117 | + BundlePropertyConfig.ID: f"validate{ID_SEP_KEY}dataset", |
| 118 | + BundlePropertyConfig.REF_ID: f"validate{ID_SEP_KEY}dataloader{ID_SEP_KEY}dataset", |
| 119 | + }, |
| 120 | + "val_dataset_data": { |
| 121 | + BundleProperty.DESC: "data source for the validation dataset.", |
| 122 | + BundleProperty.REQUIRED: False, |
| 123 | + BundlePropertyConfig.ID: f"validate{ID_SEP_KEY}dataset{ID_SEP_KEY}data", |
| 124 | + BundlePropertyConfig.REF_ID: None, # no reference to this ID |
| 125 | + }, |
| 126 | + "val_inferer": { |
| 127 | + BundleProperty.DESC: "MONAI Inferer object to execute the model computation in validation.", |
| 128 | + BundleProperty.REQUIRED: False, |
| 129 | + BundlePropertyConfig.ID: f"validate{ID_SEP_KEY}inferer", |
| 130 | + BundlePropertyConfig.REF_ID: f"validate{ID_SEP_KEY}evaluator{ID_SEP_KEY}inferer", |
| 131 | + }, |
| 132 | + "val_preprocessing": { |
| 133 | + BundleProperty.DESC: "preprocessing for the validation input data.", |
| 134 | + BundleProperty.REQUIRED: False, |
| 135 | + BundlePropertyConfig.ID: f"validate{ID_SEP_KEY}preprocessing", |
| 136 | + BundlePropertyConfig.REF_ID: f"validate{ID_SEP_KEY}dataset{ID_SEP_KEY}transform", |
| 137 | + }, |
| 138 | + "val_postprocessing": { |
| 139 | + BundleProperty.DESC: "postprocessing for the validation model output data.", |
| 140 | + BundleProperty.REQUIRED: False, |
| 141 | + BundlePropertyConfig.ID: f"validate{ID_SEP_KEY}postprocessing", |
| 142 | + BundlePropertyConfig.REF_ID: f"validate{ID_SEP_KEY}evaluator{ID_SEP_KEY}postprocessing", |
| 143 | + }, |
| 144 | + "val_key_metric": { |
| 145 | + BundleProperty.DESC: "key metric to compute on the validation data.", |
| 146 | + BundleProperty.REQUIRED: False, |
| 147 | + BundlePropertyConfig.ID: f"validate{ID_SEP_KEY}key_metric", |
| 148 | + BundlePropertyConfig.REF_ID: f"validate{ID_SEP_KEY}evaluator{ID_SEP_KEY}key_val_metric", |
| 149 | + }, |
| 150 | +} |
| 151 | + |
| 152 | + |
| 153 | +InferProperties = { |
| 154 | + "bundle_root": { |
| 155 | + BundleProperty.DESC: "root path of the bundle.", |
| 156 | + BundleProperty.REQUIRED: True, |
| 157 | + BundlePropertyConfig.ID: "bundle_root", |
| 158 | + }, |
| 159 | + "device": { |
| 160 | + BundleProperty.DESC: "target device to execute the bundle workflow.", |
| 161 | + BundleProperty.REQUIRED: True, |
| 162 | + BundlePropertyConfig.ID: "device", |
| 163 | + }, |
| 164 | + "network_def": { |
| 165 | + BundleProperty.DESC: "network module for the inference.", |
| 166 | + BundleProperty.REQUIRED: True, |
| 167 | + BundlePropertyConfig.ID: "network_def", |
| 168 | + }, |
| 169 | + "inferer": { |
| 170 | + BundleProperty.DESC: "MONAI Inferer object to execute the model computation in inference.", |
| 171 | + BundleProperty.REQUIRED: True, |
| 172 | + BundlePropertyConfig.ID: "inferer", |
| 173 | + }, |
| 174 | + "preprocessing": { |
| 175 | + BundleProperty.DESC: "preprocessing for the input data.", |
| 176 | + BundleProperty.REQUIRED: False, |
| 177 | + BundlePropertyConfig.ID: "preprocessing", |
| 178 | + BundlePropertyConfig.REF_ID: f"dataset{ID_SEP_KEY}transform", |
| 179 | + }, |
| 180 | + "postprocessing": { |
| 181 | + BundleProperty.DESC: "postprocessing for the model output data.", |
| 182 | + BundleProperty.REQUIRED: False, |
| 183 | + BundlePropertyConfig.ID: "postprocessing", |
| 184 | + BundlePropertyConfig.REF_ID: f"evaluator{ID_SEP_KEY}postprocessing", |
| 185 | + }, |
| 186 | + "key_metric": { |
| 187 | + BundleProperty.DESC: "the key metric during evaluation.", |
| 188 | + BundleProperty.REQUIRED: False, |
| 189 | + BundlePropertyConfig.ID: "key_metric", |
| 190 | + BundlePropertyConfig.REF_ID: f"evaluator{ID_SEP_KEY}key_val_metric", |
| 191 | + }, |
| 192 | +} |
0 commit comments