monai.deploy.operators.MonaiSegInferenceOperator

class monai.deploy.operators.MonaiSegInferenceOperator(roi_size, pre_transforms, post_transforms, model_name='', overlap=0.5, *args, **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.

Creates a instance of this class.

Parameters
  • roi_size (Union[Sequence[int], int]) – The tensor size used in inference.

  • pre_transforms (Compose) – MONAI Compose object used for pre-transforms.

  • post_transforms (Compose) – MONAI Compose object used for post-transforms.

  • model_name (str, optional) – Name of the model. Default to “” for single model app.

  • overlap (float) – The overlap used in sliding window inference.

Methods

__init__(roi_size, pre_transforms, …[, …])

Creates a instance of this class.

add_input(label, data_type, storage_type)

add_output(label, data_type, storage_type)

compute(op_input, op_output, context)

Infers with the input image and save the predicted image to output

ensure_valid()

Ensures that the operator is valid.

post_compute()

This method gets executed after “compute()” of an operator is called.

post_process(data, *args, **kwargs)

Transforms the prediction results from the model(s).

pre_compute()

This method gets executed before compute() of an operator is called.

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.

Attributes

MODEL_LOCAL_PATH

env

Gives access to the environment.

input_dataset_key

This is the input image key name used in dictionary based MONAI pre-transforms.

name

Returns the name of this operator.

op_info

Retrieves the operator info.

overlap

This is the overlap used during sliding window inference

pred_dataset_key

This is the prediction key name used in dictionary based MONAI post-transforms.

roi_size

The ROI size of tensors used in prediction.

uid

Gives access to the UID of the operator.

__init__(roi_size, pre_transforms, post_transforms, model_name='', overlap=0.5, *args, **kwargs)[source]

Creates a instance of this class.

Parameters
  • roi_size (Union[Sequence[int], int]) – The tensor size used in inference.

  • pre_transforms (Compose) – MONAI Compose object used for pre-transforms.

  • post_transforms (Compose) – MONAI Compose object used for post-transforms.

  • model_name (str, optional) – Name of the model. Default to “” for single model app.

  • overlap (float) – The overlap used in sliding window inference.

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.

ensure_valid()

Ensures that the operator is valid.

This method needs to be executed by add_operator() and add_flow() methods in the compose() method of the application. This sets default values for the operator in the graph if necessary. (e.g., set default value for the operator’s input port, set default value for the operator’s output port, etc.)

property env: monai.deploy.core.operator.OperatorEnv

Gives access to the environment.

This sets a default value for the operator’s environment if not set.

Return type

OperatorEnv

Returns

An instance of OperatorEnv.

property input_dataset_key

This is the input image key name used in dictionary based MONAI pre-transforms.

property name: str

Returns the name of this operator.

Return type

str

property op_info: monai.deploy.core.operator_info.OperatorInfo

Retrieves the operator info.

Args:

Return type

OperatorInfo

Returns

An instance of OperatorInfo.

property overlap

This is the overlap used during sliding window inference

post_compute()

This method gets executed after “compute()” of an operator is called.

This is a post-execution step before the operator is done doing its main action. This needs to be overridden by a base class for any meaningful action.

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

This method gets executed before compute() of an operator is called.

This is a preperatory step before the operator executes its main job. This needs to be overridden by a base class for any meaningful action.

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]]

property roi_size

The ROI size of tensors used in prediction.

property uid: uuid.UUID

Gives access to the UID of the operator.

Return type

UUID

Returns

UID of the operator.