MONAI Segmentation Inference Operator#
Authors: Holoscan SDK Team (NVIDIA)
Supported platforms: x86_64, aarch64
Language: Python
Last modified: August 5, 2025
Latest version: 1.1.0
Minimum Holoscan SDK version: 1.0.3
Tested Holoscan SDK versions: 2.2.0, 3.2.0
Contribution metric: Level 2 - Trusted
This segmentation operator uses MONAI transforms and Sliding Window Inference to segment medical images.
Overview#
The MonaiSegInferenceOperator performs pre-transforms on input images, runs segmentation inference using a specified model, and applies post-transforms. The segmentation result is returned as an in-memory image object and can optionally be saved to disk.
Requirements#
- Holoscan SDK Python package
- MONAI
- torch
Example Usage#
from pathlib import Path
import torch
from monai.transforms import Compose, LoadImage, ScaleIntensity, EnsureChannelFirst
from holoscan.core import Fragment
from operators.medical_imaging.monai_segmentation_inference_operator import MonaiSegInferenceOperator
from operators.medical_imaging.core import AppContext, IOMapping, IOType, Image
# Initialize the fragment
fragment = Fragment()
# Create app context
app_context = AppContext({})
# Define transforms
pre_transforms = Compose([
LoadImage(image_only=True),
EnsureChannelFirst(),
ScaleIntensity(),
])
post_transforms = Compose([
# Add your post-processing transforms here
])
# Initialize the segmentation operator
seg_op = MonaiSegInferenceOperator(
fragment,
roi_size=(96, 96, 96), # Example ROI size for 3D images
pre_transforms=pre_transforms,
post_transforms=post_transforms,
app_context=app_context,
model_name="unet", # Example model name
overlap=0.25,
sw_batch_size=4,
model_path=Path("/path/to/your/model.pt") # Replace with your model path
)
API Reference#
Python#
MonaiSegInferenceOperator#
Inherits from: InferenceOperator
This segmentation operator uses MONAI transforms and Sliding Window Inference.
Methods#
| Method | Description |
|---|---|
__init__(fragment) |
Creates a instance of this class. |
setup(spec) |
|
roi_size() |
The ROI size of tensors used in prediction. |
roi_size(roi_size) |
|
input_dataset_key() |
This is the input image key name used in dictionary based MONAI pre-transforms. |
input_dataset_key(val) |
|
pred_dataset_key() |
This is the prediction key name used in dictionary based MONAI post-transforms. |
pred_dataset_key(val) |
|
overlap() |
This is the overlap used during sliding window inference |
overlap(val) |
|
sw_batch_size() |
The batch size to run window slices |
sw_batch_size(val) |
|
inferer() |
The type of inferer to use |
inferer(val) |
|
compute(op_input, op_output, context) |
Infers with the input image and save the predicted image to output |
compute_impl(input_image, context) |
|
pre_process(data) |
Transforms input before being used for predicting on a model. |
post_process(data) |
Transforms the prediction results from the model(s). |
predict(data) |
Predicts results using the models(s) with input tensors. |