monai.deploy.operators.InferenceOperator

class monai.deploy.operators.InferenceOperator(*args, **kwargs)[source]

Bases: monai.deploy.core.operator.Operator

The base operator for operators that perform AI inference.

This operator preforms pre-transforms on a input image, inference with a given model, post-transforms, and final results generation.

Constructor of the operator.

Methods

__init__(*args, **kwargs)

Constructor of the operator.

add_input(label, data_type, storage_type)

add_output(label, data_type, storage_type)

compute(op_input, op_output, context)

An abstract method that needs to be implemented by the user.

ensure_valid()

Ensures that the operator is valid.

post_compute()

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

post_process(data)

Transform the prediction results from the model(s).

pre_compute()

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

pre_process(data)

Transforms input before being used for predicting on a model.

predict(data)

Prdicts results using the models(s) with input tensors.

Attributes

env

Gives access to the environment.

name

Returns the name of this operator.

op_info

Retrieves the operator info.

uid

Gives access to the UID of the operator.

__init__(*args, **kwargs)[source]

Constructor of the operator.

abstract compute(op_input, op_output, context)[source]

An abstract method that needs to be implemented by the user.

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

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.

abstract post_process(data)[source]

Transform the prediction results from the model(s).

This method must be overridden by a derived class.

Raises

NotImplementedError – When the subclass does not override this method.

Return type

Union[Image, Any]

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.

abstract pre_process(data)[source]

Transforms input before being used for predicting on a model.

This method must be overridden by a derived class.

Raises

NotImplementedError – When the subclass does not override this method.

Return type

Union[Image, Any]

abstract predict(data)[source]

Prdicts results using the models(s) with input tensors.

This method must be overridden by a derived class.

Raises

NotImplementedError – When the subclass does not override this method.

Return type

Union[Image, Any]

property uid: uuid.UUID

Gives access to the UID of the operator.

Return type

UUID

Returns

UID of the operator.