monai.deploy.operators.MonaiSegInferenceOperator¶
- class monai.deploy.operators.MonaiSegInferenceOperator(fragment, *args, roi_size, pre_transforms, post_transforms, app_context, model_name='', overlap=0.25, sw_batch_size=4, inferer=InfererType.SLIDING_WINDOW, model_path=PosixPath('/home/docs/checkouts/readthedocs.org/user_builds/monai-deploy-app-sdk/checkouts/latest/docs/source/model/model.ts'), **kwargs)[source]¶
Bases:
monai.deploy.operators.inference_operator.InferenceOperator
This segmentation operator uses MONAI transforms and Sliding Window Inference.
This operator preforms pre-transforms on a input image, inference using a given model, and post-transforms. The segmentation image is saved as a named Image object in memory.
If specified in the post transforms, results may also be saved to disk.
- Named Input:
image: Image object of the input image.
- Named Output:
seg_image: Image object of the segmentation image. Not requiring a ready receiver.
Creates a instance of this class.
- Parameters
fragment (Fragment) – An instance of the Application class which is derived from Fragment.
roi_size (Union[Sequence[int], int]) – The window size to execute “SLIDING_WINDOW” evaluation. An optional input only to be passed for “SLIDING_WINDOW”. If using a “SIMPLE” Inferer, this input is ignored.
pre_transforms (Compose) – MONAI Compose object used for pre-transforms.
post_transforms (Compose) – MONAI Compose object used for post-transforms.
app_context (AppContext) – Object holding the I/O and model paths, and potentially loaded models.
model_name (str, optional) – Name of the model. Default to “” for single model app.
overlap (float) – The amount of overlap between scans along each spatial dimension. Defaults to 0.25. Applicable for “SLIDING_WINDOW” only.
sw_batch_size (int) – The batch size to run window slices. Defaults to 4. Applicable for “SLIDING_WINDOW” only.
inferer (InfererType) – The type of inferer to use, “SIMPLE” or “SLIDING_WINDOW”. Defaults to “SLIDING_WINDOW”.
model_path (Path) – Path to the model file. Defaults to model/models.ts of current working dir.
Methods
__init__
(fragment, *args, roi_size, …[, …])Creates a instance of this class.
add_arg
(*args, **kwargs)Overloaded function.
compute
(op_input, op_output, context)Infers with the input image and save the predicted image to output
compute_impl
(input_image, context)Default implementation of initialize
post_process
(data, *args, **kwargs)Transforms the prediction results from the model(s).
pre_process
(data, *args, **kwargs)Transforms input before being used for predicting on a model.
predict
(data, *args, **kwargs)Predicts results using the models(s) with input tensors.
resource
(self, name)Resources associated with the operator.
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.
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.
The type of inferer to use
This is the input image key name used in dictionary based MONAI pre-transforms.
The name of the operator.
The operator type.
This is the overlap used during sliding window inference
This is the prediction key name used in dictionary based MONAI post-transforms.
Resources associated with the operator.
The ROI size of tensors used in prediction.
The operator spec (
holoscan.core.OperatorSpec
) associated with the operator.The batch size to run window slices
- 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, roi_size, pre_transforms, post_transforms, app_context, model_name='', overlap=0.25, sw_batch_size=4, inferer=InfererType.SLIDING_WINDOW, model_path=PosixPath('/home/docs/checkouts/readthedocs.org/user_builds/monai-deploy-app-sdk/checkouts/latest/docs/source/model/model.ts'), **kwargs)[source]¶
Creates a instance of this class.
- Parameters
fragment (Fragment) – An instance of the Application class which is derived from Fragment.
roi_size (Union[Sequence[int], int]) – The window size to execute “SLIDING_WINDOW” evaluation. An optional input only to be passed for “SLIDING_WINDOW”. If using a “SIMPLE” Inferer, this input is ignored.
pre_transforms (Compose) – MONAI Compose object used for pre-transforms.
post_transforms (Compose) – MONAI Compose object used for post-transforms.
app_context (AppContext) – Object holding the I/O and model paths, and potentially loaded models.
model_name (str, optional) – Name of the model. Default to “” for single model app.
overlap (float) – The amount of overlap between scans along each spatial dimension. Defaults to 0.25. Applicable for “SLIDING_WINDOW” only.
sw_batch_size (int) – The batch size to run window slices. Defaults to 4. Applicable for “SLIDING_WINDOW” only.
inferer (InfererType) – The type of inferer to use, “SIMPLE” or “SLIDING_WINDOW”. Defaults to “SLIDING_WINDOW”.
model_path (Path) – Path to the model file. Defaults to model/models.ts of current working dir.
- 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
- compute(op_input, op_output, context)[source]¶
Infers with the input image and save the predicted image 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
- property inferer: Union[monai.deploy.operators.monai_seg_inference_operator.InfererType, str]¶
The type of inferer to use
- Return type
Union
[InfererType
,str
]
- initialize()¶
Default implementation of initialize
- property input_dataset_key¶
This is the input image key name used in dictionary based MONAI pre-transforms.
- 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 overlap¶
This is the overlap used during sliding window inference
- post_process(data, *args, **kwargs)[source]¶
Transforms the prediction results from the model(s).
This method must be overridden by a derived class. Expected return is monai.transforms.Compose.
- Parameters
data (monai.transforms.Compose) – The pre-processing transforms in a Compose object.
- Return type
Union
[Any
,Image
,Tuple
[Any
, …],Dict
[Any
,Any
]]- Returns
monai.transforms.Compose encapsulating post-processing transforms.
- Raises
NotImplementedError – When the subclass does not override this method.
- pre_process(data, *args, **kwargs)[source]¶
Transforms input before being used for predicting on a model.
This method must be overridden by a derived class. Expected return is monai.transforms.Compose.
- Parameters
data (monai.data.ImageReader) – Reader used in LoadImage to load monai.deploy.core.Image as the input.
- Return type
Union
[Any
,Image
,Tuple
[Any
, …],Dict
[Any
,Any
]]- Returns
monai.transforms.Compose encapsulating pre transforms
- Raises
NotImplementedError – When the subclass does not override this method.
- property pred_dataset_key¶
This is the prediction key name used in dictionary based MONAI post-transforms.
- predict(data, *args, **kwargs)[source]¶
Predicts results using the models(s) with input tensors.
This method is currently not used in this class, instead monai.inferers.sliding_window_inference is used.
- Raises
NotImplementedError – When the subclass does not override this method.
- Return type
Union
[Image
,Any
,Tuple
[Any
, …],Dict
[Any
,Any
]]
- resource(self: holoscan.core._core.Operator, name: str) Optional[object] ¶
Resources associated with the operator.
name : str The name of the resource to retrieve
- holoscan.core.Resource or None
The resource with the given name. If no resource with the given name is found, None is returned.
- property resources¶
Resources associated with the operator.
- property roi_size¶
The ROI size of tensors used in prediction.
- property spec¶
The operator spec (
holoscan.core.OperatorSpec
) associated with the operator.
- start()¶
Default implementation of start
- stop()¶
Default implementation of stop
- property sw_batch_size¶
The batch size to run window slices