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

initialize(self)

Operator initialization method.

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(self)

Operator start method.

stop(self)

Operator stop method.

Attributes

MODEL_LOCAL_PATH

args

The list of arguments associated with the component.

bundle_path

The path of the MONAI Bundle model.

conditions

Conditions associated with the operator.

description

YAML formatted string describing the operator.

fragment

The fragment that the operator belongs to.

id

The identifier of the component.

known_io_data_types

kw_preprocessed_inputs

model_name

rtype

str

name

The name of the operator.

operator_type

The operator type.

parser

The ConfigParser object.

resources

Resources associated with the operator.

spec

class OperatorType(self: holoscan.core._core.Operator.OperatorType, value: int) None

Bases: pybind11_builtins.pybind11_object

Members:

NATIVE

GXF

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.

  1. add_arg(self: holoscan.core._core.Component, arg: holoscan.core._core.Arg) -> None

Add an argument to the component.

  1. add_arg(self: holoscan.core._core.Component, arg: holoscan.core._core.ArgList) -> None

Add a list of arguments to the component.

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 that the operator belongs to.

name : holoscan.core.Fragment

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(self: holoscan.core._core.Operator) None

Operator initialization method.

property name

The name of the operator.

name : str

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.

setup(spec)[source]

Default implementation of setup method.

start(self: holoscan.core._core.Operator) None

Operator start method.

stop(self: holoscan.core._core.Operator) None

Operator stop method.