monai.deploy.operators.MonaiBundleInferenceOperator¶
- class monai.deploy.operators.MonaiBundleInferenceOperator(fragment, *args, app_context, input_mapping, output_mapping, model_name='', bundle_path=None, bundle_config_names=<monai.deploy.operators.monai_bundle_inference_operator.BundleConfigNames object>, **kwargs)[source]¶
Bases:
monai.deploy.operators.inference_operator.InferenceOperator
This inference operator automates the inference operation for a given MONAI Bundle.
This inference operator configures itself based on the parsed data from a MONAI bundle file. This file is included with a MAP as a Torchscript file with added bundle metadata or a zipped bundle with weights. The class will configure how to do pre- and post-processing, inference, which device to use, state its inputs, outputs, and dependencies. Its compute method is meant to be general purpose to most any bundle such that it will handle any input specified in the bundle and produce output as specified, using the inference object the bundle defines. A number of methods are provided which define parts of functionality relating to this behavior, users may wish to overwrite these to change behavior is needed for specific bundles.
The input(s) and output(s) for this operator need to be provided when an instance is created, and their labels need to correspond to the bundle network input and output names, which are also used as the keys in the pre and post processing.
For image input and output, the type is the Image class. For output of probabilities, the type is Dict.
This operator is expected to be linked with both source and destination operators, e.g. receiving an Image object from the DICOMSeriesToVolumeOperator, and passing a segmentation Image to the DICOMSegmentationWriterOperator. In such cases, the I/O storage type can only be IN_MEMORY due to the restrictions imposed by the application executor.
For the time being, the input and output to this operator are limited to in_memory object.
Create an instance of this class, associated with an Application/Fragment.
- Parameters
fragment (Fragment) – An instance of the Application class which is derived from Fragment.
app_context (AppContext) – Object holding the I/O and model paths, and potentially loaded models.
input_mapping (List[IOMapping]) – Define the inputs’ name, type, and storage type.
output_mapping (List[IOMapping]) – Defines the outputs’ name, type, and storage type.
model_name (Optional[str], optional) – Name of the model/bundle, needed in multi-model case. Defaults to “”.
bundle_path (Optional[str], optional) – Known path to the bundle file. Defaults to None.
bundle_config_names (BundleConfigNames, optional) – Relevant config item names in a the bundle. Defaults to DEFAULT_BundleConfigNames.
Methods
__init__
(fragment, *args, app_context, …)Create an instance of this class, associated with an Application/Fragment.
add_arg
(*args, **kwargs)Overloaded function.
compute
(op_input, op_output, context)Infers with the input(s) and saves the prediction result(s) to output
Default implementation of initialize
post_process
(data, *args, **kwargs)Processes the output list/dictionary with the stored transform sequence self._postproc.
pre_process
(data, *args, **kwargs)Processes the input dictionary with the stored transform sequence self._preproc.
predict
(data, *args, **kwargs)Predicts output using the inferer.
setup
(spec)Default implementation of setup method.
start
()Default implementation of start
stop
()Default implementation of stop
Attributes
MODEL_LOCAL_PATH
The list of arguments associated with the component.
The path of the MONAI Bundle model.
Conditions associated with the operator.
YAML formatted string describing the operator.
The fragment (
holoscan.core.Fragment
) that the operator belongs to.The identifier of the component.
known_io_data_types
kw_preprocessed_inputs
model_name
- rtype
str
The name of the operator.
The operator type.
The ConfigParser object.
Resources associated with the operator.
The operator spec (
holoscan.core.OperatorSpec
) associated with the operator.- class OperatorType(self: holoscan.core._core.Operator.OperatorType, value: int) None ¶
Bases:
pybind11_builtins.pybind11_object
Enum class for operator types used by the executor.
NATIVE: Native operator.
GXF: GXF operator.
VIRTUAL: Virtual operator. (for internal use, not intended for use by application authors)
Members:
NATIVE
GXF
VIRTUAL
- property name¶
- __init__(fragment, *args, app_context, input_mapping, output_mapping, model_name='', bundle_path=None, bundle_config_names=<monai.deploy.operators.monai_bundle_inference_operator.BundleConfigNames object>, **kwargs)[source]¶
Create an instance of this class, associated with an Application/Fragment.
- Parameters
fragment (Fragment) – An instance of the Application class which is derived from Fragment.
app_context (AppContext) – Object holding the I/O and model paths, and potentially loaded models.
input_mapping (List[IOMapping]) – Define the inputs’ name, type, and storage type.
output_mapping (List[IOMapping]) – Defines the outputs’ name, type, and storage type.
model_name (Optional[str], optional) – Name of the model/bundle, needed in multi-model case. Defaults to “”.
bundle_path (Optional[str], optional) – Known path to the bundle file. Defaults to None.
bundle_config_names (BundleConfigNames, optional) – Relevant config item names in a the bundle. Defaults to DEFAULT_BundleConfigNames.
- add_arg(*args, **kwargs)¶
Overloaded function.
add_arg(self: holoscan.core._core.Operator, arg: holoscan.core._core.Arg) -> None
Add an argument to the component.
add_arg(self: holoscan.core._core.Operator, arg: holoscan.core._core.ArgList) -> None
Add a list of arguments to the component.
add_arg(self: holoscan.core._core.Operator, **kwargs) -> None
Add arguments to the component via Python kwargs.
add_arg(self: holoscan.core._core.Operator, arg: holoscan.core._core.Condition) -> None
add_arg(self: holoscan.core._core.Operator, arg: holoscan.core._core.Resource) -> None
Add a condition or resource to the Operator.
This can be used to add a condition or resource to an operator after it has already been constructed.
- argholoscan.core.Condition or holoscan.core.Resource
The condition or resource to add.
- property args¶
The list of arguments associated with the component.
arglist : holoscan.core.ArgList
- property bundle_path: Optional[pathlib.Path]¶
The path of the MONAI Bundle model.
- Return type
Optional
[Path
]
- compute(op_input, op_output, context)[source]¶
Infers with the input(s) and saves the prediction result(s) to output
- Parameters
op_input (InputContext) – An input context for the operator.
op_output (OutputContext) – An output context for the operator.
context (ExecutionContext) – An execution context for the operator.
- property conditions¶
Conditions associated with the operator.
- property description¶
YAML formatted string describing the operator.
- property fragment¶
The fragment (
holoscan.core.Fragment
) that the operator belongs to.
- property id¶
The identifier of the component.
The identifier is initially set to
-1
, and will become a valid value when the component is initialized.With the default executor (holoscan.gxf.GXFExecutor), the identifier is set to the GXF component ID.
id : int
- initialize()¶
Default implementation of initialize
- property name¶
The name of the operator.
- property operator_type¶
The operator type.
holoscan.core.Operator.OperatorType enum representing the type of the operator. The two types currently implemented are native and GXF.
- property parser: Optional[monai.bundle.config_parser.ConfigParser]¶
The ConfigParser object.
- Return type
Optional
[ConfigParser
]
- post_process(data, *args, **kwargs)[source]¶
Processes the output list/dictionary with the stored transform sequence self._postproc.
The “processed_inputs”, in fact the metadata in it, need to be passed in so that the invertible transforms in the post processing can work properly.
- Return type
Union
[Image
,Any
,Tuple
[Any
, …],Dict
[Any
,Any
]]
- pre_process(data, *args, **kwargs)[source]¶
Processes the input dictionary with the stored transform sequence self._preproc.
- Return type
Union
[Image
,Any
,Tuple
[Any
, …],Dict
[Any
,Any
]]
- predict(data, *args, **kwargs)[source]¶
Predicts output using the inferer.
- Return type
Union
[Image
,Any
,Tuple
[Any
, …],Dict
[Any
,Any
]]
- property resources¶
Resources associated with the operator.
- property spec¶
The operator spec (
holoscan.core.OperatorSpec
) associated with the operator.
- start()¶
Default implementation of start
- stop()¶
Default implementation of stop