Deploying a MedNIST Classifier App with MONAI Deploy App SDK

This tutorial demos the process of packaging up a trained model using MONAI Deploy App SDK into an artifact which can be run as a local program performing inference, a workflow job doing the same, and a Docker containerized workflow execution.

In this tutorial, we will train a MedNIST classifier like the MONAI tutorial here and then implement & package the inference application, executing the application locally.

Train a MedNIST classifier model with MONAI Core

Setup environment

# Install necessary packages for MONAI Core
!python -c "import monai" || pip install -q "monai[pillow, tqdm]"
!python -c "import ignite" || pip install -q "monai[ignite]"
!python -c "import gdown" || pip install -q "monai[gdown]"
!python -c "import pydicom" || pip install -q "pydicom>=1.4.2"
!python -c "import highdicom" || pip install -q "highdicom>=0.18.2"  # for the use of DICOM Writer operators

# Install MONAI Deploy App SDK package
!python -c "import monai.deploy" || pip install -q "monai-deploy-app-sdk"

Setup imports

# Copyright 2020 MONAI Consortium
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#     http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import os
import shutil
import tempfile
import glob
import PIL.Image
import torch
import numpy as np

from ignite.engine import Events

from monai.apps import download_and_extract
from monai.config import print_config
from monai.networks.nets import DenseNet121
from monai.engines import SupervisedTrainer
from monai.transforms import (
    EnsureChannelFirst,
    Compose,
    LoadImage,
    RandFlip,
    RandRotate,
    RandZoom,
    ScaleIntensity,
    EnsureType,
)
from monai.utils import set_determinism

set_determinism(seed=0)

print_config()
MONAI version: 1.3.0
Numpy version: 1.26.4
Pytorch version: 2.0.1+cu117
MONAI flags: HAS_EXT = False, USE_COMPILED = False, USE_META_DICT = False
MONAI rev id: 865972f7a791bf7b42efbcd87c8402bd865b329e
MONAI __file__: /home/<username>/src/monai-deploy-app-sdk/.venv/lib/python3.10/site-packages/monai/__init__.py

Optional dependencies:
Pytorch Ignite version: 0.4.11
ITK version: NOT INSTALLED or UNKNOWN VERSION.
Nibabel version: 5.2.1
scikit-image version: 0.23.2
scipy version: 1.13.0
Pillow version: 10.3.0
Tensorboard version: NOT INSTALLED or UNKNOWN VERSION.
gdown version: 4.7.3
TorchVision version: NOT INSTALLED or UNKNOWN VERSION.
tqdm version: 4.66.2
lmdb version: NOT INSTALLED or UNKNOWN VERSION.
psutil version: 5.9.6
pandas version: NOT INSTALLED or UNKNOWN VERSION.
einops version: NOT INSTALLED or UNKNOWN VERSION.
transformers version: NOT INSTALLED or UNKNOWN VERSION.
mlflow version: NOT INSTALLED or UNKNOWN VERSION.
pynrrd version: NOT INSTALLED or UNKNOWN VERSION.
clearml version: NOT INSTALLED or UNKNOWN VERSION.

For details about installing the optional dependencies, please visit:
    https://docs.monai.io/en/latest/installation.html#installing-the-recommended-dependencies

Download dataset

The MedNIST dataset was gathered from several sets from TCIA, the RSNA Bone Age Challenge(https://www.rsna.org/education/ai-resources-and-training/ai-image-challenge/rsna-pediatric-bone-age-challenge-2017), and the NIH Chest X-ray dataset.

The dataset is kindly made available by Dr. Bradley J. Erickson M.D., Ph.D. (Department of Radiology, Mayo Clinic) under the Creative Commons CC BY-SA 4.0 license.

If you use the MedNIST dataset, please acknowledge the source.

directory = os.environ.get("MONAI_DATA_DIRECTORY")
root_dir = tempfile.mkdtemp() if directory is None else directory
print(root_dir)

resource = "https://drive.google.com/uc?id=1QsnnkvZyJPcbRoV_ArW8SnE1OTuoVbKE"
md5 = "0bc7306e7427e00ad1c5526a6677552d"

compressed_file = os.path.join(root_dir, "MedNIST.tar.gz")
data_dir = os.path.join(root_dir, "MedNIST")
if not os.path.exists(data_dir):
    download_and_extract(resource, compressed_file, root_dir, md5)
/tmp/tmp0iht_c0l
Downloading...
From (original): https://drive.google.com/uc?id=1QsnnkvZyJPcbRoV_ArW8SnE1OTuoVbKE
From (redirected): https://drive.google.com/uc?id=1QsnnkvZyJPcbRoV_ArW8SnE1OTuoVbKE&confirm=t&uuid=af0469cc-fefc-4bd4-9ba2-60e15ffc2168
To: /tmp/tmpquityog6/MedNIST.tar.gz
100%|██████████| 61.8M/61.8M [00:00<00:00, 66.5MB/s]
2024-04-23 17:01:37,537 - INFO - Downloaded: /tmp/tmp0iht_c0l/MedNIST.tar.gz

2024-04-23 17:01:37,643 - INFO - Verified 'MedNIST.tar.gz', md5: 0bc7306e7427e00ad1c5526a6677552d.
2024-04-23 17:01:37,644 - INFO - Writing into directory: /tmp/tmp0iht_c0l.
subdirs = sorted(glob.glob(f"{data_dir}/*/"))

class_names = [os.path.basename(sd[:-1]) for sd in subdirs]
image_files = [glob.glob(f"{sb}/*") for sb in subdirs]

image_files_list = sum(image_files, [])
image_class = sum(([i] * len(f) for i, f in enumerate(image_files)), [])
image_width, image_height = PIL.Image.open(image_files_list[0]).size

print(f"Label names: {class_names}")
print(f"Label counts: {list(map(len, image_files))}")
print(f"Total image count: {len(image_class)}")
print(f"Image dimensions: {image_width} x {image_height}")
Label names: ['AbdomenCT', 'BreastMRI', 'CXR', 'ChestCT', 'Hand', 'HeadCT']
Label counts: [10000, 8954, 10000, 10000, 10000, 10000]
Total image count: 58954
Image dimensions: 64 x 64

Setup and train

Here we’ll create a transform sequence and train the network, omitting validation and testing since we know this does indeed work and it’s not needed here:

train_transforms = Compose(
    [
        LoadImage(image_only=True),
        EnsureChannelFirst(channel_dim="no_channel"),
        ScaleIntensity(),
        RandRotate(range_x=np.pi / 12, prob=0.5, keep_size=True),
        RandFlip(spatial_axis=0, prob=0.5),
        RandZoom(min_zoom=0.9, max_zoom=1.1, prob=0.5),
        EnsureType(),
    ]
)
class MedNISTDataset(torch.utils.data.Dataset):
    def __init__(self, image_files, labels, transforms):
        self.image_files = image_files
        self.labels = labels
        self.transforms = transforms

    def __len__(self):
        return len(self.image_files)

    def __getitem__(self, index):
        return self.transforms(self.image_files[index]), self.labels[index]


# just one dataset and loader, we won't bother with validation or testing 
train_ds = MedNISTDataset(image_files_list, image_class, train_transforms)
train_loader = torch.utils.data.DataLoader(train_ds, batch_size=300, shuffle=True, num_workers=10)
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
net = DenseNet121(spatial_dims=2, in_channels=1, out_channels=len(class_names)).to(device)
loss_function = torch.nn.CrossEntropyLoss()
opt = torch.optim.Adam(net.parameters(), 1e-5)
max_epochs = 5
def _prepare_batch(batch, device, non_blocking):
    return tuple(b.to(device) for b in batch)


trainer = SupervisedTrainer(device, max_epochs, train_loader, net, opt, loss_function, prepare_batch=_prepare_batch)


@trainer.on(Events.EPOCH_COMPLETED)
def _print_loss(engine):
    print(f"Epoch {engine.state.epoch}/{engine.state.max_epochs} Loss: {engine.state.output[0]['loss']}")


trainer.run()
Epoch 1/5 Loss: 0.18928290903568268
Epoch 2/5 Loss: 0.06710730493068695
Epoch 3/5 Loss: 0.029032323509454727
Epoch 4/5 Loss: 0.01877668686211109
Epoch 5/5 Loss: 0.01939055137336254

The network will be saved out here as a Torchscript object named classifier.zip

torch.jit.script(net).save("classifier.zip")

Implementing and Packaging Application with MONAI Deploy App SDK

Based on the Torchscript model(classifier.zip), we will implement an application that process an input Jpeg image and write the prediction(classification) result as JSON file(output.json).

Creating Operators and connecting them in Application class

We used the following train transforms as pre-transforms during the training.

Train transforms used in training
 1train_transforms = Compose(
 2    [
 3        LoadImage(image_only=True),
 4        EnsureChannelFirst(channel_dim="no_channel"),
 5        ScaleIntensity(),
 6        RandRotate(range_x=np.pi / 12, prob=0.5, keep_size=True),
 7        RandFlip(spatial_axis=0, prob=0.5),
 8        RandZoom(min_zoom=0.9, max_zoom=1.1, prob=0.5),
 9        EnsureType(),
10    ]
11)

RandRotate, RandFlip, and RandZoom transforms are used only for training and those are not necessary during the inference.

In our inference application, we will define two operators:

  1. LoadPILOperator - Load a JPEG image from the input path and pass the loaded image object to the next operator.

    • This Operator does similar job with LoadImage(image_only=True) transform in train_transforms, but handles only one image.

    • Input: a file path (Path)

    • Output: an image object in memory (Image)

  2. MedNISTClassifierOperator - Pre-transform the given image by using MONAI’s Compose class, feed to the Torchscript model (classifier.zip), and write the prediction into JSON file(output.json)

    • Pre-transforms consist of three transforms – EnsureChannelFirst, ScaleIntensity, and EnsureType.

    • Input: an image object in memory (Image)

    • Output: a folder path that the prediction result(output.json) would be written (DataPath)

The workflow of the application would look like this.

%%{init: {"theme": "base", "themeVariables": { "fontSize": "16px"}} }%% classDiagram direction LR LoadPILOperator --|> MedNISTClassifierOperator : image...image class LoadPILOperator { <in>image : DISK image(out) IN_MEMORY } class MedNISTClassifierOperator { <in>image : IN_MEMORY output(out) DISK }

Set up environment variables

Before proceeding to the application building and packaging, we first need to set the well-known environment variables, because the application parses them for the input, output, and model folders. Defaults are used if these environment variable are absent.

Set the environment variables corresponding to the extracted data path.

input_folder = "input"
output_foler = "output"
models_folder = "models"

# Choose a file as test input
test_input_path = image_files[0][0]
!rm -rf {input_folder} && mkdir -p {input_folder} && cp {test_input_path} {input_folder} && ls {input_folder}
# Need to copy the model file to its own clean subfolder for pacakging, to workaround an issue in the Packager
!rm -rf {models_folder} && mkdir -p {models_folder}/model && cp classifier.zip {models_folder}/model && ls {models_folder}/model

%env HOLOSCAN_INPUT_PATH {input_folder}
%env HOLOSCAN_OUTPUT_PATH {output_foler}
%env HOLOSCAN_MODEL_PATH {models_folder}
001420.jpeg
classifier.zip
env: HOLOSCAN_INPUT_PATH=input
env: HOLOSCAN_OUTPUT_PATH=output
env: HOLOSCAN_MODEL_PATH=models

Setup imports

Let’s import necessary classes/decorators and define MEDNIST_CLASSES.

import logging
import os
from pathlib import Path
from typing import Optional

import torch

from monai.deploy.conditions import CountCondition
from monai.deploy.core import AppContext, Application, ConditionType, Fragment, Image, Operator, OperatorSpec
from monai.deploy.operators.dicom_text_sr_writer_operator import DICOMTextSRWriterOperator, EquipmentInfo, ModelInfo
from monai.transforms import EnsureChannelFirst, Compose, EnsureType, ScaleIntensity

MEDNIST_CLASSES = ["AbdomenCT", "BreastMRI", "CXR", "ChestCT", "Hand", "HeadCT"]

Creating Operator classes

LoadPILOperator
class LoadPILOperator(Operator):
    """Load image from the given input (DataPath) and set numpy array to the output (Image)."""

    DEFAULT_INPUT_FOLDER = Path.cwd() / "input"
    DEFAULT_OUTPUT_NAME = "image"

    # For now, need to have the input folder as an instance attribute, set on init.
    # If dynamically changing the input folder, per compute, then use a (optional) input port to convey the
    # value of the input folder, which is then emitted by a upstream operator.
    def __init__(
        self,
        fragment: Fragment,
        *args,
        input_folder: Path = DEFAULT_INPUT_FOLDER,
        output_name: str = DEFAULT_OUTPUT_NAME,
        **kwargs,
    ):
        """Creates an loader object with the input folder and the output port name overrides as needed.

        Args:
            fragment (Fragment): An instance of the Application class which is derived from Fragment.
            input_folder (Path): Folder from which to load input file(s).
                                 Defaults to `input` in the current working directory.
            output_name (str): Name of the output port, which is an image object. Defaults to `image`.
        """

        self._logger = logging.getLogger("{}.{}".format(__name__, type(self).__name__))
        self.input_path = input_folder
        self.index = 0
        self.output_name_image = (
            output_name.strip() if output_name and len(output_name.strip()) > 0 else LoadPILOperator.DEFAULT_OUTPUT_NAME
        )

        super().__init__(fragment, *args, **kwargs)

    def setup(self, spec: OperatorSpec):
        """Set up the named input and output port(s)"""
        spec.output(self.output_name_image)

    def compute(self, op_input, op_output, context):
        import numpy as np
        from PIL import Image as PILImage

        # Input path is stored in the object attribute, but could change to use a named port if need be.
        input_path = self.input_path
        if input_path.is_dir():
            input_path = next(self.input_path.glob("*.*"))  # take the first file

        image = PILImage.open(input_path)
        image = image.convert("L")  # convert to greyscale image
        image_arr = np.asarray(image)

        output_image = Image(image_arr)  # create Image domain object with a numpy array
        op_output.emit(output_image, self.output_name_image)  # cannot omit the name even if single output.
MedNISTClassifierOperator
class MedNISTClassifierOperator(Operator):
    """Classifies the given image and returns the class name.

    Named inputs:
        image: Image object for which to generate the classification.
        output_folder: Optional, the path to save the results JSON file, overridingthe the one set on __init__

    Named output:
        result_text: The classification results in text.
    """

    DEFAULT_OUTPUT_FOLDER = Path.cwd() / "classification_results"
    # For testing the app directly, the model should be at the following path.
    MODEL_LOCAL_PATH = Path(os.environ.get("HOLOSCAN_MODEL_PATH", Path.cwd() / "model/model.ts"))

    def __init__(
        self,
        frament: Fragment,
        *args,
        app_context: AppContext,
        model_name: Optional[str] = "",
        model_path: Path = MODEL_LOCAL_PATH,
        output_folder: Path = DEFAULT_OUTPUT_FOLDER,
        **kwargs,
    ):
        """Creates an instance with the reference back to the containing application/fragment.

        fragment (Fragment): An instance of the Application class which is derived from Fragment.
        model_name (str, optional): Name of the model. Default to "" for single model app.
        model_path (Path): Path to the model file. Defaults to model/models.ts of current working dir.
        output_folder (Path, optional): output folder for saving the classification results JSON file.
        """

        # the names used for the model inference input and output
        self._input_dataset_key = "image"
        self._pred_dataset_key = "pred"

        # The names used for the operator input and output
        self.input_name_image = "image"
        self.output_name_result = "result_text"

        # The name of the optional input port for passing data to override the output folder path.
        self.input_name_output_folder = "output_folder"

        # The output folder set on the object can be overriden at each compute by data in the optional named input
        self.output_folder = output_folder

        # Need the name when there are multiple models loaded
        self._model_name = model_name.strip() if isinstance(model_name, str) else ""
        # Need the path to load the models when they are not loaded in the execution context
        self.model_path = model_path
        self.app_context = app_context
        self.model = self._get_model(self.app_context, self.model_path, self._model_name)

        # This needs to be at the end of the constructor.
        super().__init__(frament, *args, **kwargs)

    def _get_model(self, app_context: AppContext, model_path: Path, model_name: str):
        """Load the model with the given name from context or model path

        Args:
            app_context (AppContext): The application context object holding the model(s)
            model_path (Path): The path to the model file, as a backup to load model directly
            model_name (str): The name of the model, when multiples are loaded in the context
        """

        if app_context.models:
            # `app_context.models.get(model_name)` returns a model instance if exists.
            # If model_name is not specified and only one model exists, it returns that model.
            model = app_context.models.get(model_name)
        else:
            model = torch.jit.load(
                MedNISTClassifierOperator.MODEL_LOCAL_PATH,
                map_location=torch.device("cuda" if torch.cuda.is_available() else "cpu"),
            )

        return model

    def setup(self, spec: OperatorSpec):
        """Set up the operator named input and named output, both are in-memory objects."""

        spec.input(self.input_name_image)
        spec.input(self.input_name_output_folder).condition(ConditionType.NONE)  # Optional for overriding.
        spec.output(self.output_name_result).condition(ConditionType.NONE)  # Not forcing a downstream receiver.

    @property
    def transform(self):
        return Compose([EnsureChannelFirst(channel_dim="no_channel"), ScaleIntensity(), EnsureType()])

    def compute(self, op_input, op_output, context):
        import json

        import torch

        img = op_input.receive(self.input_name_image).asnumpy()  # (64, 64), uint8. Input validation can be added.
        image_tensor = self.transform(img)  # (1, 64, 64), torch.float64
        image_tensor = image_tensor[None].float()  # (1, 1, 64, 64), torch.float32

        device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
        image_tensor = image_tensor.to(device)

        with torch.no_grad():
            outputs = self.model(image_tensor)

        _, output_classes = outputs.max(dim=1)

        result = MEDNIST_CLASSES[output_classes[0]]  # get the class name
        print(result)
        op_output.emit(result, self.output_name_result)

        # Get output folder, with value in optional input port overriding the obj attribute
        output_folder_on_compute = op_input.receive(self.input_name_output_folder) or self.output_folder
        Path.mkdir(output_folder_on_compute, parents=True, exist_ok=True)  # Let exception bubble up if raised.
        output_path = output_folder_on_compute / "output.json"
        with open(output_path, "w") as fp:
            json.dump(result, fp)

Creating Application class

Our application class would look like below.

It defines App class inheriting Application class.

LoadPILOperator is connected to MedNISTClassifierOperator by using self.add_flow() in compose() method of App.

class App(Application):
    """Application class for the MedNIST classifier."""

    def compose(self):
        app_context = Application.init_app_context({})  # Do not pass argv in Jupyter Notebook
        app_input_path = Path(app_context.input_path)
        app_output_path = Path(app_context.output_path)
        model_path = Path(app_context.model_path)
        load_pil_op = LoadPILOperator(self, CountCondition(self, 1), input_folder=app_input_path, name="pil_loader_op")
        classifier_op = MedNISTClassifierOperator(
            self, app_context=app_context, output_folder=app_output_path, model_path=model_path, name="classifier_op"
        )

        my_model_info = ModelInfo("MONAI WG Trainer", "MEDNIST Classifier", "0.1", "xyz")
        my_equipment = EquipmentInfo(manufacturer="MOANI Deploy App SDK", manufacturer_model="DICOM SR Writer")
        my_special_tags = {"SeriesDescription": "Not for clinical use. The result is for research use only."}
        dicom_sr_operator = DICOMTextSRWriterOperator(
            self,
            copy_tags=False,
            model_info=my_model_info,
            equipment_info=my_equipment,
            custom_tags=my_special_tags,
            output_folder=app_output_path,
        )

        self.add_flow(load_pil_op, classifier_op, {("image", "image")})
        self.add_flow(classifier_op, dicom_sr_operator, {("result_text", "text")})

Executing app locally

The test input file file, output path, and model have been prepared, and the paths set in the environment variables, so we can go ahead and execute the application Jupyter notebook with a clean output folder.

!rm -rf $HOLOSCAN_OUTPUT_PATH
app = App().run()
[2024-04-23 17:08:56,466] [INFO] (root) - Parsed args: Namespace(log_level=None, input=None, output=None, model=None, workdir=None, argv=[])
[2024-04-23 17:08:56,478] [INFO] (root) - AppContext object: AppContext(input_path=input, output_path=output, model_path=models, workdir=)
2024-04-23 17:08:56.514 INFO  gxf/std/greedy_scheduler.cpp@191: Scheduling 3 entities
[info] [gxf_executor.cpp:247] Creating context
[info] [gxf_executor.cpp:1672] Loading extensions from configs...
[info] [gxf_executor.cpp:1842] Activating Graph...
[info] [gxf_executor.cpp:1874] Running Graph...
[info] [gxf_executor.cpp:1876] Waiting for completion...
/home/mqin/src/monai-deploy-app-sdk/.venv/lib/python3.10/site-packages/monai/data/meta_tensor.py:116: UserWarning: The given NumPy array is not writable, and PyTorch does not support non-writable tensors. This means writing to this tensor will result in undefined behavior. You may want to copy the array to protect its data or make it writable before converting it to a tensor. This type of warning will be suppressed for the rest of this program. (Triggered internally at ../torch/csrc/utils/tensor_numpy.cpp:206.)
  return torch.as_tensor(x, *args, **_kwargs).as_subclass(cls)
/home/mqin/src/monai-deploy-app-sdk/.venv/lib/python3.10/site-packages/pydicom/valuerep.py:443: UserWarning: Invalid value for VR UI: 'xyz'. Please see <https://dicom.nema.org/medical/dicom/current/output/html/part05.html#table_6.2-1> for allowed values for each VR.
  warnings.warn(msg)
[2024-04-23 17:08:57,259] [INFO] (root) - Finished writing DICOM instance to file output/1.2.826.0.1.3680043.8.498.77299510031662020162686125612902317163.dcm
[2024-04-23 17:08:57,261] [INFO] (monai.deploy.operators.dicom_text_sr_writer_operator.DICOMTextSRWriterOperator) - DICOM SOP instance saved in output/1.2.826.0.1.3680043.8.498.77299510031662020162686125612902317163.dcm
AbdomenCT
2024-04-23 17:08:57.263 INFO  gxf/std/greedy_scheduler.cpp@372: Scheduler stopped: Some entities are waiting for execution, but there are no periodic or async entities to get out of the deadlock.
2024-04-23 17:08:57.263 INFO  gxf/std/greedy_scheduler.cpp@401: Scheduler finished.
[info] [gxf_executor.cpp:1879] Deactivating Graph...
[info] [gxf_executor.cpp:1887] Graph execution finished.
[info] [gxf_executor.cpp:275] Destroying context
!cat $HOLOSCAN_OUTPUT_PATH/output.json
"AbdomenCT"

Once the application is verified inside Jupyter notebook, we can write the whole application as a file(mednist_classifier_monaideploy.py) by concatenating code above, then add the following lines:

if __name__ == "__main__":
    App()

The above lines are needed to execute the application code by using python interpreter.

# Create an application folder
!mkdir -p mednist_app
!rm -rf mednist_app/*
%%writefile mednist_app/mednist_classifier_monaideploy.py

# Copyright 2021-2023 MONAI Consortium
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#     http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import logging
import os
from pathlib import Path
from typing import Optional

import torch

from monai.deploy.conditions import CountCondition
from monai.deploy.core import AppContext, Application, ConditionType, Fragment, Image, Operator, OperatorSpec
from monai.deploy.operators.dicom_text_sr_writer_operator import DICOMTextSRWriterOperator, EquipmentInfo, ModelInfo
from monai.transforms import EnsureChannelFirst, Compose, EnsureType, ScaleIntensity

MEDNIST_CLASSES = ["AbdomenCT", "BreastMRI", "CXR", "ChestCT", "Hand", "HeadCT"]


# @md.env(pip_packages=["pillow"])
class LoadPILOperator(Operator):
    """Load image from the given input (DataPath) and set numpy array to the output (Image)."""

    DEFAULT_INPUT_FOLDER = Path.cwd() / "input"
    DEFAULT_OUTPUT_NAME = "image"

    # For now, need to have the input folder as an instance attribute, set on init.
    # If dynamically changing the input folder, per compute, then use a (optional) input port to convey the
    # value of the input folder, which is then emitted by a upstream operator.
    def __init__(
        self,
        fragment: Fragment,
        *args,
        input_folder: Path = DEFAULT_INPUT_FOLDER,
        output_name: str = DEFAULT_OUTPUT_NAME,
        **kwargs,
    ):
        """Creates an loader object with the input folder and the output port name overrides as needed.

        Args:
            fragment (Fragment): An instance of the Application class which is derived from Fragment.
            input_folder (Path): Folder from which to load input file(s).
                                 Defaults to `input` in the current working directory.
            output_name (str): Name of the output port, which is an image object. Defaults to `image`.
        """

        self._logger = logging.getLogger("{}.{}".format(__name__, type(self).__name__))
        self.input_path = input_folder
        self.index = 0
        self.output_name_image = (
            output_name.strip() if output_name and len(output_name.strip()) > 0 else LoadPILOperator.DEFAULT_OUTPUT_NAME
        )

        super().__init__(fragment, *args, **kwargs)

    def setup(self, spec: OperatorSpec):
        """Set up the named input and output port(s)"""
        spec.output(self.output_name_image)

    def compute(self, op_input, op_output, context):
        import numpy as np
        from PIL import Image as PILImage

        # Input path is stored in the object attribute, but could change to use a named port if need be.
        input_path = self.input_path
        if input_path.is_dir():
            input_path = next(self.input_path.glob("*.*"))  # take the first file

        image = PILImage.open(input_path)
        image = image.convert("L")  # convert to greyscale image
        image_arr = np.asarray(image)

        output_image = Image(image_arr)  # create Image domain object with a numpy array
        op_output.emit(output_image, self.output_name_image)  # cannot omit the name even if single output.


# @md.env(pip_packages=["monai"])
class MedNISTClassifierOperator(Operator):
    """Classifies the given image and returns the class name.

    Named inputs:
        image: Image object for which to generate the classification.
        output_folder: Optional, the path to save the results JSON file, overridingthe the one set on __init__

    Named output:
        result_text: The classification results in text.
    """

    DEFAULT_OUTPUT_FOLDER = Path.cwd() / "classification_results"
    # For testing the app directly, the model should be at the following path.
    MODEL_LOCAL_PATH = Path(os.environ.get("HOLOSCAN_MODEL_PATH", Path.cwd() / "model/model.ts"))

    def __init__(
        self,
        frament: Fragment,
        *args,
        app_context: AppContext,
        model_name: Optional[str] = "",
        model_path: Path = MODEL_LOCAL_PATH,
        output_folder: Path = DEFAULT_OUTPUT_FOLDER,
        **kwargs,
    ):
        """Creates an instance with the reference back to the containing application/fragment.

        fragment (Fragment): An instance of the Application class which is derived from Fragment.
        model_name (str, optional): Name of the model. Default to "" for single model app.
        model_path (Path): Path to the model file. Defaults to model/models.ts of current working dir.
        output_folder (Path, optional): output folder for saving the classification results JSON file.
        """

        # the names used for the model inference input and output
        self._input_dataset_key = "image"
        self._pred_dataset_key = "pred"

        # The names used for the operator input and output
        self.input_name_image = "image"
        self.output_name_result = "result_text"

        # The name of the optional input port for passing data to override the output folder path.
        self.input_name_output_folder = "output_folder"

        # The output folder set on the object can be overriden at each compute by data in the optional named input
        self.output_folder = output_folder

        # Need the name when there are multiple models loaded
        self._model_name = model_name.strip() if isinstance(model_name, str) else ""
        # Need the path to load the models when they are not loaded in the execution context
        self.model_path = model_path
        self.app_context = app_context
        self.model = self._get_model(self.app_context, self.model_path, self._model_name)

        # This needs to be at the end of the constructor.
        super().__init__(frament, *args, **kwargs)

    def _get_model(self, app_context: AppContext, model_path: Path, model_name: str):
        """Load the model with the given name from context or model path

        Args:
            app_context (AppContext): The application context object holding the model(s)
            model_path (Path): The path to the model file, as a backup to load model directly
            model_name (str): The name of the model, when multiples are loaded in the context
        """

        if app_context.models:
            # `app_context.models.get(model_name)` returns a model instance if exists.
            # If model_name is not specified and only one model exists, it returns that model.
            model = app_context.models.get(model_name)
        else:
            model = torch.jit.load(
                MedNISTClassifierOperator.MODEL_LOCAL_PATH,
                map_location=torch.device("cuda" if torch.cuda.is_available() else "cpu"),
            )

        return model

    def setup(self, spec: OperatorSpec):
        """Set up the operator named input and named output, both are in-memory objects."""

        spec.input(self.input_name_image)
        spec.input(self.input_name_output_folder).condition(ConditionType.NONE)  # Optional for overriding.
        spec.output(self.output_name_result).condition(ConditionType.NONE)  # Not forcing a downstream receiver.

    @property
    def transform(self):
        return Compose([EnsureChannelFirst(channel_dim="no_channel"), ScaleIntensity(), EnsureType()])

    def compute(self, op_input, op_output, context):
        import json

        import torch

        img = op_input.receive(self.input_name_image).asnumpy()  # (64, 64), uint8. Input validation can be added.
        image_tensor = self.transform(img)  # (1, 64, 64), torch.float64
        image_tensor = image_tensor[None].float()  # (1, 1, 64, 64), torch.float32

        device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
        image_tensor = image_tensor.to(device)

        with torch.no_grad():
            outputs = self.model(image_tensor)

        _, output_classes = outputs.max(dim=1)

        result = MEDNIST_CLASSES[output_classes[0]]  # get the class name
        print(result)
        op_output.emit(result, self.output_name_result)

        # Get output folder, with value in optional input port overriding the obj attribute
        output_folder_on_compute = op_input.receive(self.input_name_output_folder) or self.output_folder
        Path.mkdir(output_folder_on_compute, parents=True, exist_ok=True)  # Let exception bubble up if raised.
        output_path = output_folder_on_compute / "output.json"
        with open(output_path, "w") as fp:
            json.dump(result, fp)


# @md.resource(cpu=1, gpu=1, memory="1Gi")
class App(Application):
    """Application class for the MedNIST classifier."""

    def compose(self):
        app_context = AppContext({})  # Let it figure out all the attributes without overriding
        app_input_path = Path(app_context.input_path)
        app_output_path = Path(app_context.output_path)
        model_path = Path(app_context.model_path)
        load_pil_op = LoadPILOperator(self, CountCondition(self, 1), input_folder=app_input_path, name="pil_loader_op")
        classifier_op = MedNISTClassifierOperator(
            self, app_context=app_context, output_folder=app_output_path, model_path=model_path, name="classifier_op"
        )

        my_model_info = ModelInfo("MONAI WG Trainer", "MEDNIST Classifier", "0.1", "xyz")
        my_equipment = EquipmentInfo(manufacturer="MOANI Deploy App SDK", manufacturer_model="DICOM SR Writer")
        my_special_tags = {"SeriesDescription": "Not for clinical use. The result is for research use only."}
        dicom_sr_operator = DICOMTextSRWriterOperator(
            self,
            copy_tags=False,
            model_info=my_model_info,
            equipment_info=my_equipment,
            custom_tags=my_special_tags,
            output_folder=app_output_path,
        )

        self.add_flow(load_pil_op, classifier_op, {("image", "image")})
        self.add_flow(classifier_op, dicom_sr_operator, {("result_text", "text")})


if __name__ == "__main__":
    App().run()
Writing mednist_app/mednist_classifier_monaideploy.py

This time, let’s execute the app in the command line.

!python "mednist_app/mednist_classifier_monaideploy.py"
[info] [gxf_executor.cpp:247] Creating context
[info] [gxf_executor.cpp:1672] Loading extensions from configs...
[info] [gxf_executor.cpp:1842] Activating Graph...
[info] [gxf_executor.cpp:1874] Running Graph...
[info] [gxf_executor.cpp:1876] Waiting for completion...
2024-04-23 17:09:01.847 INFO  gxf/std/greedy_scheduler.cpp@191: Scheduling 3 entities
/home/mqin/src/monai-deploy-app-sdk/.venv/lib/python3.10/site-packages/monai/data/meta_tensor.py:116: UserWarning: The given NumPy array is not writable, and PyTorch does not support non-writable tensors. This means writing to this tensor will result in undefined behavior. You may want to copy the array to protect its data or make it writable before converting it to a tensor. This type of warning will be suppressed for the rest of this program. (Triggered internally at ../torch/csrc/utils/tensor_numpy.cpp:206.)
  return torch.as_tensor(x, *args, **_kwargs).as_subclass(cls)
AbdomenCT
/home/mqin/src/monai-deploy-app-sdk/.venv/lib/python3.10/site-packages/pydicom/valuerep.py:443: UserWarning: Invalid value for VR UI: 'xyz'. Please see <https://dicom.nema.org/medical/dicom/current/output/html/part05.html#table_6.2-1> for allowed values for each VR.
  warnings.warn(msg)
2024-04-23 17:09:03.971 INFO  gxf/std/greedy_scheduler.cpp@372: Scheduler stopped: Some entities are waiting for execution, but there are no periodic or async entities to get out of the deadlock.
2024-04-23 17:09:03.971 INFO  gxf/std/greedy_scheduler.cpp@401: Scheduler finished.
[info] [gxf_executor.cpp:1879] Deactivating Graph...
[info] [gxf_executor.cpp:1887] Graph execution finished.
[info] [gxf_executor.cpp:275] Destroying context
!cat $HOLOSCAN_OUTPUT_PATH/output.json
"AbdomenCT"

Packaging app

Let’s package the app with MONAI Application Packager.

In this version of the App SDK, we need to write out the configuration yaml file as well as the package requirements file, in the application folder.

%%writefile mednist_app/app.yaml
%YAML 1.2
---
application:
  title: MONAI Deploy App Package - MedNIST Classifier App
  version: 1.0
  inputFormats: ["file"]
  outputFormats: ["file"]

resources:
  cpu: 1
  gpu: 1
  memory: 1Gi
  gpuMemory: 1Gi
Writing mednist_app/app.yaml
%%writefile mednist_app/requirements.txt
monai>=1.2.0
Pillow>=8.4.0
pydicom>=2.3.0
highdicom>=0.18.2
SimpleITK>=2.0.0
setuptools>=59.5.0 # for pkg_resources
Writing mednist_app/requirements.txt
tag_prefix = "mednist_app"

!monai-deploy package "mednist_app/mednist_classifier_monaideploy.py" -m {models_folder} -c "mednist_app/app.yaml" -t {tag_prefix}:1.0 --platform x64-workstation -l DEBUG
[2024-04-23 17:09:06,108] [INFO] (common) - Downloading CLI manifest file...
[2024-04-23 17:09:06,368] [DEBUG] (common) - Validating CLI manifest file...
[2024-04-23 17:09:06,371] [INFO] (packager.parameters) - Application: /home/mqin/src/monai-deploy-app-sdk/notebooks/tutorials/mednist_app/mednist_classifier_monaideploy.py
[2024-04-23 17:09:06,372] [INFO] (packager.parameters) - Detected application type: Python File
[2024-04-23 17:09:06,372] [INFO] (packager) - Scanning for models in /home/mqin/src/monai-deploy-app-sdk/notebooks/tutorials/models...
[2024-04-23 17:09:06,373] [DEBUG] (packager) - Model model=/home/mqin/src/monai-deploy-app-sdk/notebooks/tutorials/models/model added.
[2024-04-23 17:09:06,373] [INFO] (packager) - Reading application configuration from /home/mqin/src/monai-deploy-app-sdk/notebooks/tutorials/mednist_app/app.yaml...
[2024-04-23 17:09:06,378] [INFO] (packager) - Generating app.json...
[2024-04-23 17:09:06,379] [INFO] (packager) - Generating pkg.json...
[2024-04-23 17:09:06,393] [DEBUG] (common) - 
=============== Begin app.json ===============
{
    "apiVersion": "1.0.0",
    "command": "[\"python3\", \"/opt/holoscan/app/mednist_classifier_monaideploy.py\"]",
    "environment": {
        "HOLOSCAN_APPLICATION": "/opt/holoscan/app",
        "HOLOSCAN_INPUT_PATH": "input/",
        "HOLOSCAN_OUTPUT_PATH": "output/",
        "HOLOSCAN_WORKDIR": "/var/holoscan",
        "HOLOSCAN_MODEL_PATH": "/opt/holoscan/models",
        "HOLOSCAN_CONFIG_PATH": "/var/holoscan/app.yaml",
        "HOLOSCAN_APP_MANIFEST_PATH": "/etc/holoscan/app.json",
        "HOLOSCAN_PKG_MANIFEST_PATH": "/etc/holoscan/pkg.json",
        "HOLOSCAN_DOCS_PATH": "/opt/holoscan/docs",
        "HOLOSCAN_LOGS_PATH": "/var/holoscan/logs"
    },
    "input": {
        "path": "input/",
        "formats": null
    },
    "liveness": null,
    "output": {
        "path": "output/",
        "formats": null
    },
    "readiness": null,
    "sdk": "monai-deploy",
    "sdkVersion": "0.5.1",
    "timeout": 0,
    "version": 1.0,
    "workingDirectory": "/var/holoscan"
}
================ End app.json ================
                 
[2024-04-23 17:09:06,393] [DEBUG] (common) - 
=============== Begin pkg.json ===============
{
    "apiVersion": "1.0.0",
    "applicationRoot": "/opt/holoscan/app",
    "modelRoot": "/opt/holoscan/models",
    "models": {
        "model": "/opt/holoscan/models/model"
    },
    "resources": {
        "cpu": 1,
        "gpu": 1,
        "memory": "1Gi",
        "gpuMemory": "1Gi"
    },
    "version": 1.0,
    "platformConfig": "dgpu"
}
================ End pkg.json ================
                 
[2024-04-23 17:09:06,435] [DEBUG] (packager.builder) - 
========== Begin Dockerfile ==========


FROM nvcr.io/nvidia/clara-holoscan/holoscan:v2.0.0-dgpu

ENV DEBIAN_FRONTEND=noninteractive
ENV TERM=xterm-256color

ARG UNAME
ARG UID
ARG GID

RUN mkdir -p /etc/holoscan/ \
        && mkdir -p /opt/holoscan/ \
        && mkdir -p /var/holoscan \
        && mkdir -p /opt/holoscan/app \
        && mkdir -p /var/holoscan/input \
        && mkdir -p /var/holoscan/output

LABEL base="nvcr.io/nvidia/clara-holoscan/holoscan:v2.0.0-dgpu"
LABEL tag="mednist_app:1.0"
LABEL org.opencontainers.image.title="MONAI Deploy App Package - MedNIST Classifier App"
LABEL org.opencontainers.image.version="1.0"
LABEL org.nvidia.holoscan="2.0.0"
LABEL org.monai.deploy.app-sdk="0.5.1"


ENV HOLOSCAN_ENABLE_HEALTH_CHECK=true
ENV HOLOSCAN_INPUT_PATH=/var/holoscan/input
ENV HOLOSCAN_OUTPUT_PATH=/var/holoscan/output
ENV HOLOSCAN_WORKDIR=/var/holoscan
ENV HOLOSCAN_APPLICATION=/opt/holoscan/app
ENV HOLOSCAN_TIMEOUT=0
ENV HOLOSCAN_MODEL_PATH=/opt/holoscan/models
ENV HOLOSCAN_DOCS_PATH=/opt/holoscan/docs
ENV HOLOSCAN_CONFIG_PATH=/var/holoscan/app.yaml
ENV HOLOSCAN_APP_MANIFEST_PATH=/etc/holoscan/app.json
ENV HOLOSCAN_PKG_MANIFEST_PATH=/etc/holoscan/pkg.json
ENV HOLOSCAN_LOGS_PATH=/var/holoscan/logs
ENV PATH=/root/.local/bin:/opt/nvidia/holoscan:$PATH
ENV LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/libtorch/1.13.1/lib/:/opt/nvidia/holoscan/lib

RUN apt-get update \
    && apt-get install -y curl jq \
    && rm -rf /var/lib/apt/lists/*

ENV PYTHONPATH="/opt/holoscan/app:$PYTHONPATH"


RUN groupadd -f -g $GID $UNAME
RUN useradd -rm -d /home/$UNAME -s /bin/bash -g $GID -G sudo -u $UID $UNAME
RUN chown -R holoscan /var/holoscan 
RUN chown -R holoscan /var/holoscan/input 
RUN chown -R holoscan /var/holoscan/output 

# Set the working directory
WORKDIR /var/holoscan

# Copy HAP/MAP tool script
COPY ./tools /var/holoscan/tools
RUN chmod +x /var/holoscan/tools


# Copy gRPC health probe

USER $UNAME

ENV PATH=/root/.local/bin:/home/holoscan/.local/bin:/opt/nvidia/holoscan:$PATH

COPY ./pip/requirements.txt /tmp/requirements.txt

RUN pip install --upgrade pip
RUN pip install --no-cache-dir --user -r /tmp/requirements.txt

 
# MONAI Deploy

# Copy user-specified MONAI Deploy SDK file
COPY ./monai_deploy_app_sdk-0.5.1+20.gb869749.dirty-py3-none-any.whl /tmp/monai_deploy_app_sdk-0.5.1+20.gb869749.dirty-py3-none-any.whl
RUN pip install /tmp/monai_deploy_app_sdk-0.5.1+20.gb869749.dirty-py3-none-any.whl


COPY ./models  /opt/holoscan/models

COPY ./map/app.json /etc/holoscan/app.json
COPY ./app.config /var/holoscan/app.yaml
COPY ./map/pkg.json /etc/holoscan/pkg.json

COPY ./app /opt/holoscan/app

ENTRYPOINT ["/var/holoscan/tools"]
=========== End Dockerfile ===========

[2024-04-23 17:09:06,435] [INFO] (packager.builder) - 
===============================================================================
Building image for:                 x64-workstation
    Architecture:                   linux/amd64
    Base Image:                     nvcr.io/nvidia/clara-holoscan/holoscan:v2.0.0-dgpu
    Build Image:                    N/A
    Cache:                          Enabled
    Configuration:                  dgpu
    Holoscan SDK Package:           pypi.org
    MONAI Deploy App SDK Package:   /home/mqin/src/monai-deploy-app-sdk/dist/monai_deploy_app_sdk-0.5.1+20.gb869749.dirty-py3-none-any.whl
    gRPC Health Probe:              N/A
    SDK Version:                    2.0.0
    SDK:                            monai-deploy
    Tag:                            mednist_app-x64-workstation-dgpu-linux-amd64:1.0
    
[2024-04-23 17:09:06,753] [INFO] (common) - Using existing Docker BuildKit builder `holoscan_app_builder`
[2024-04-23 17:09:06,753] [DEBUG] (packager.builder) - Building Holoscan Application Package: tag=mednist_app-x64-workstation-dgpu-linux-amd64:1.0
#0 building with "holoscan_app_builder" instance using docker-container driver

#1 [internal] load build definition from Dockerfile
#1 transferring dockerfile: 2.67kB done
#1 DONE 0.0s

#2 [internal] load metadata for nvcr.io/nvidia/clara-holoscan/holoscan:v2.0.0-dgpu
#2 DONE 0.4s

#3 [internal] load .dockerignore
#3 transferring context: 1.79kB done
#3 DONE 0.0s

#4 [internal] load build context
#4 DONE 0.0s

#5 importing cache manifest from local:14814255791215325379
#5 inferred cache manifest type: application/vnd.oci.image.index.v1+json done
#5 DONE 0.0s

#6 [ 1/21] FROM nvcr.io/nvidia/clara-holoscan/holoscan:v2.0.0-dgpu@sha256:20adbccd2c7b12dfb1798f6953f071631c3b85cd337858a7506f8e420add6d4a
#6 resolve nvcr.io/nvidia/clara-holoscan/holoscan:v2.0.0-dgpu@sha256:20adbccd2c7b12dfb1798f6953f071631c3b85cd337858a7506f8e420add6d4a 0.0s done
#6 DONE 0.0s

#7 importing cache manifest from nvcr.io/nvidia/clara-holoscan/holoscan:v2.0.0-dgpu
#7 inferred cache manifest type: application/vnd.docker.distribution.manifest.list.v2+json done
#7 DONE 0.6s

#4 [internal] load build context
#4 transferring context: 28.76MB 0.2s done
#4 DONE 0.2s

#8 [ 6/21] RUN chown -R holoscan /var/holoscan
#8 CACHED

#9 [ 3/21] RUN apt-get update     && apt-get install -y curl jq     && rm -rf /var/lib/apt/lists/*
#9 CACHED

#10 [ 5/21] RUN useradd -rm -d /home/holoscan -s /bin/bash -g 1000 -G sudo -u 1000 holoscan
#10 CACHED

#11 [10/21] COPY ./tools /var/holoscan/tools
#11 CACHED

#12 [ 4/21] RUN groupadd -f -g 1000 holoscan
#12 CACHED

#13 [12/21] COPY ./pip/requirements.txt /tmp/requirements.txt
#13 CACHED

#14 [ 7/21] RUN chown -R holoscan /var/holoscan/input
#14 CACHED

#15 [ 8/21] RUN chown -R holoscan /var/holoscan/output
#15 CACHED

#16 [13/21] RUN pip install --upgrade pip
#16 CACHED

#17 [ 9/21] WORKDIR /var/holoscan
#17 CACHED

#18 [ 2/21] RUN mkdir -p /etc/holoscan/         && mkdir -p /opt/holoscan/         && mkdir -p /var/holoscan         && mkdir -p /opt/holoscan/app         && mkdir -p /var/holoscan/input         && mkdir -p /var/holoscan/output
#18 CACHED

#19 [11/21] RUN chmod +x /var/holoscan/tools
#19 CACHED

#20 [14/21] RUN pip install --no-cache-dir --user -r /tmp/requirements.txt
#20 CACHED

#21 [15/21] COPY ./monai_deploy_app_sdk-0.5.1+20.gb869749.dirty-py3-none-any.whl /tmp/monai_deploy_app_sdk-0.5.1+20.gb869749.dirty-py3-none-any.whl
#21 DONE 0.2s

#22 [16/21] RUN pip install /tmp/monai_deploy_app_sdk-0.5.1+20.gb869749.dirty-py3-none-any.whl
#22 0.646 Defaulting to user installation because normal site-packages is not writeable
#22 0.740 Processing /tmp/monai_deploy_app_sdk-0.5.1+20.gb869749.dirty-py3-none-any.whl
#22 0.751 Requirement already satisfied: numpy>=1.21.6 in /usr/local/lib/python3.10/dist-packages (from monai-deploy-app-sdk==0.5.1+20.gb869749.dirty) (1.23.5)
#22 0.850 Collecting holoscan~=2.0 (from monai-deploy-app-sdk==0.5.1+20.gb869749.dirty)
#22 0.921   Downloading holoscan-2.0.0-cp310-cp310-manylinux_2_35_x86_64.whl.metadata (6.7 kB)
#22 0.978 Collecting colorama>=0.4.1 (from monai-deploy-app-sdk==0.5.1+20.gb869749.dirty)
#22 0.982   Downloading colorama-0.4.6-py2.py3-none-any.whl.metadata (17 kB)
#22 1.026 Collecting typeguard>=3.0.0 (from monai-deploy-app-sdk==0.5.1+20.gb869749.dirty)
#22 1.030   Downloading typeguard-4.2.1-py3-none-any.whl.metadata (3.7 kB)
#22 1.044 Requirement already satisfied: pip>=20.3 in /home/holoscan/.local/lib/python3.10/site-packages (from holoscan~=2.0->monai-deploy-app-sdk==0.5.1+20.gb869749.dirty) (24.0)
#22 1.045 Requirement already satisfied: cupy-cuda12x==12.2 in /usr/local/lib/python3.10/dist-packages (from holoscan~=2.0->monai-deploy-app-sdk==0.5.1+20.gb869749.dirty) (12.2.0)
#22 1.045 Requirement already satisfied: cloudpickle==2.2.1 in /usr/local/lib/python3.10/dist-packages (from holoscan~=2.0->monai-deploy-app-sdk==0.5.1+20.gb869749.dirty) (2.2.1)
#22 1.046 Requirement already satisfied: python-on-whales==0.60.1 in /usr/local/lib/python3.10/dist-packages (from holoscan~=2.0->monai-deploy-app-sdk==0.5.1+20.gb869749.dirty) (0.60.1)
#22 1.047 Requirement already satisfied: Jinja2==3.1.3 in /usr/local/lib/python3.10/dist-packages (from holoscan~=2.0->monai-deploy-app-sdk==0.5.1+20.gb869749.dirty) (3.1.3)
#22 1.048 Requirement already satisfied: packaging==23.1 in /usr/local/lib/python3.10/dist-packages (from holoscan~=2.0->monai-deploy-app-sdk==0.5.1+20.gb869749.dirty) (23.1)
#22 1.048 Requirement already satisfied: pyyaml==6.0 in /usr/local/lib/python3.10/dist-packages (from holoscan~=2.0->monai-deploy-app-sdk==0.5.1+20.gb869749.dirty) (6.0)
#22 1.049 Requirement already satisfied: requests==2.31.0 in /usr/local/lib/python3.10/dist-packages (from holoscan~=2.0->monai-deploy-app-sdk==0.5.1+20.gb869749.dirty) (2.31.0)
#22 1.050 Requirement already satisfied: psutil==5.9.6 in /usr/local/lib/python3.10/dist-packages (from holoscan~=2.0->monai-deploy-app-sdk==0.5.1+20.gb869749.dirty) (5.9.6)
#22 1.070 Collecting wheel-axle-runtime<1.0 (from holoscan~=2.0->monai-deploy-app-sdk==0.5.1+20.gb869749.dirty)
#22 1.075   Downloading wheel_axle_runtime-0.0.5-py3-none-any.whl.metadata (7.7 kB)
#22 1.107 Requirement already satisfied: fastrlock>=0.5 in /usr/local/lib/python3.10/dist-packages (from cupy-cuda12x==12.2->holoscan~=2.0->monai-deploy-app-sdk==0.5.1+20.gb869749.dirty) (0.8.2)
#22 1.112 Requirement already satisfied: MarkupSafe>=2.0 in /usr/local/lib/python3.10/dist-packages (from Jinja2==3.1.3->holoscan~=2.0->monai-deploy-app-sdk==0.5.1+20.gb869749.dirty) (2.1.3)
#22 1.126 Requirement already satisfied: pydantic<2,>=1.5 in /usr/local/lib/python3.10/dist-packages (from python-on-whales==0.60.1->holoscan~=2.0->monai-deploy-app-sdk==0.5.1+20.gb869749.dirty) (1.10.15)
#22 1.126 Requirement already satisfied: tqdm in /usr/local/lib/python3.10/dist-packages (from python-on-whales==0.60.1->holoscan~=2.0->monai-deploy-app-sdk==0.5.1+20.gb869749.dirty) (4.66.2)
#22 1.127 Requirement already satisfied: typer>=0.4.1 in /usr/local/lib/python3.10/dist-packages (from python-on-whales==0.60.1->holoscan~=2.0->monai-deploy-app-sdk==0.5.1+20.gb869749.dirty) (0.12.3)
#22 1.128 Requirement already satisfied: typing-extensions in /home/holoscan/.local/lib/python3.10/site-packages (from python-on-whales==0.60.1->holoscan~=2.0->monai-deploy-app-sdk==0.5.1+20.gb869749.dirty) (4.11.0)
#22 1.135 Requirement already satisfied: charset-normalizer<4,>=2 in /usr/local/lib/python3.10/dist-packages (from requests==2.31.0->holoscan~=2.0->monai-deploy-app-sdk==0.5.1+20.gb869749.dirty) (3.3.2)
#22 1.136 Requirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.10/dist-packages (from requests==2.31.0->holoscan~=2.0->monai-deploy-app-sdk==0.5.1+20.gb869749.dirty) (3.7)
#22 1.137 Requirement already satisfied: urllib3<3,>=1.21.1 in /usr/local/lib/python3.10/dist-packages (from requests==2.31.0->holoscan~=2.0->monai-deploy-app-sdk==0.5.1+20.gb869749.dirty) (2.2.1)
#22 1.137 Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.10/dist-packages (from requests==2.31.0->holoscan~=2.0->monai-deploy-app-sdk==0.5.1+20.gb869749.dirty) (2024.2.2)
#22 1.155 Requirement already satisfied: filelock in /home/holoscan/.local/lib/python3.10/site-packages (from wheel-axle-runtime<1.0->holoscan~=2.0->monai-deploy-app-sdk==0.5.1+20.gb869749.dirty) (3.13.4)
#22 1.176 Requirement already satisfied: click>=8.0.0 in /usr/local/lib/python3.10/dist-packages (from typer>=0.4.1->python-on-whales==0.60.1->holoscan~=2.0->monai-deploy-app-sdk==0.5.1+20.gb869749.dirty) (8.1.7)
#22 1.177 Requirement already satisfied: shellingham>=1.3.0 in /usr/local/lib/python3.10/dist-packages (from typer>=0.4.1->python-on-whales==0.60.1->holoscan~=2.0->monai-deploy-app-sdk==0.5.1+20.gb869749.dirty) (1.5.4)
#22 1.178 Requirement already satisfied: rich>=10.11.0 in /usr/local/lib/python3.10/dist-packages (from typer>=0.4.1->python-on-whales==0.60.1->holoscan~=2.0->monai-deploy-app-sdk==0.5.1+20.gb869749.dirty) (13.7.1)
#22 1.212 Requirement already satisfied: markdown-it-py>=2.2.0 in /usr/local/lib/python3.10/dist-packages (from rich>=10.11.0->typer>=0.4.1->python-on-whales==0.60.1->holoscan~=2.0->monai-deploy-app-sdk==0.5.1+20.gb869749.dirty) (3.0.0)
#22 1.213 Requirement already satisfied: pygments<3.0.0,>=2.13.0 in /usr/local/lib/python3.10/dist-packages (from rich>=10.11.0->typer>=0.4.1->python-on-whales==0.60.1->holoscan~=2.0->monai-deploy-app-sdk==0.5.1+20.gb869749.dirty) (2.17.2)
#22 1.233 Requirement already satisfied: mdurl~=0.1 in /usr/local/lib/python3.10/dist-packages (from markdown-it-py>=2.2.0->rich>=10.11.0->typer>=0.4.1->python-on-whales==0.60.1->holoscan~=2.0->monai-deploy-app-sdk==0.5.1+20.gb869749.dirty) (0.1.2)
#22 1.245 Downloading colorama-0.4.6-py2.py3-none-any.whl (25 kB)
#22 1.260 Downloading holoscan-2.0.0-cp310-cp310-manylinux_2_35_x86_64.whl (33.2 MB)
#22 1.691    ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 33.2/33.2 MB 46.8 MB/s eta 0:00:00
#22 1.696 Downloading typeguard-4.2.1-py3-none-any.whl (34 kB)
#22 1.709 Downloading wheel_axle_runtime-0.0.5-py3-none-any.whl (12 kB)
#22 2.033 Installing collected packages: wheel-axle-runtime, typeguard, colorama, holoscan, monai-deploy-app-sdk
#22 2.711 Successfully installed colorama-0.4.6 holoscan-2.0.0 monai-deploy-app-sdk-0.5.1+20.gb869749.dirty typeguard-4.2.1 wheel-axle-runtime-0.0.5
#22 DONE 3.0s

#23 [17/21] COPY ./models  /opt/holoscan/models
#23 DONE 0.2s

#24 [18/21] COPY ./map/app.json /etc/holoscan/app.json
#24 DONE 0.0s

#25 [19/21] COPY ./app.config /var/holoscan/app.yaml
#25 DONE 0.0s

#26 [20/21] COPY ./map/pkg.json /etc/holoscan/pkg.json
#26 DONE 0.1s

#27 [21/21] COPY ./app /opt/holoscan/app
#27 DONE 0.0s

#28 exporting to docker image format
#28 exporting layers
#28 exporting layers 4.4s done
#28 exporting manifest sha256:457dd7263681b35a427e304797922e6c9c1a453deadebb6e234e5d3f63947b18 0.0s done
#28 exporting config sha256:63c2bd27a2230b0ee99597a2475f434ae68969da3a8328b78d7d5bc277409172 0.0s done
#28 sending tarball
#28 ...

#29 importing to docker
#29 loading layer 36f9dbeb2e4f 238B / 238B
#29 loading layer 5828d73ee0ce 65.54kB / 5.86MB
#29 loading layer f50931954a7a 557.06kB / 2.90GB
#29 loading layer f50931954a7a 122.00MB / 2.90GB 6.2s
#29 loading layer f50931954a7a 330.89MB / 2.90GB 10.3s
#29 loading layer f50931954a7a 511.93MB / 2.90GB 14.4s
#29 loading layer f50931954a7a 681.28MB / 2.90GB 18.5s
#29 loading layer f50931954a7a 840.60MB / 2.90GB 22.6s
#29 loading layer f50931954a7a 1.05GB / 2.90GB 26.8s
#29 loading layer f50931954a7a 1.26GB / 2.90GB 30.9s
#29 loading layer f50931954a7a 1.43GB / 2.90GB 35.0s
#29 loading layer f50931954a7a 1.64GB / 2.90GB 39.0s
#29 loading layer f50931954a7a 1.89GB / 2.90GB 43.1s
#29 loading layer f50931954a7a 1.98GB / 2.90GB 50.1s
#29 loading layer f50931954a7a 2.10GB / 2.90GB 56.4s
#29 loading layer f50931954a7a 2.30GB / 2.90GB 62.4s
#29 loading layer f50931954a7a 2.47GB / 2.90GB 66.5s
#29 loading layer f50931954a7a 2.67GB / 2.90GB 70.6s
#29 loading layer f50931954a7a 2.84GB / 2.90GB 76.8s
#29 loading layer 6e852bd260ad 32.77kB / 125.82kB
#29 loading layer d8a5c55be301 557.06kB / 67.35MB
#29 loading layer 82e6702b8274 262.14kB / 26.20MB
#29 loading layer d1b690ac41a7 513B / 513B
#29 loading layer a85ba680dedd 318B / 318B
#29 loading layer 7e4618ac3cb0 297B / 297B
#29 loading layer 43922422e132 4.00kB / 4.00kB
#29 loading layer 5828d73ee0ce 65.54kB / 5.86MB 82.3s done
#29 loading layer 36f9dbeb2e4f 238B / 238B 82.4s done
#29 loading layer f50931954a7a 2.84GB / 2.90GB 81.6s done
#29 loading layer 6e852bd260ad 32.77kB / 125.82kB 3.0s done
#29 loading layer d8a5c55be301 557.06kB / 67.35MB 2.9s done
#29 loading layer 82e6702b8274 262.14kB / 26.20MB 1.1s done
#29 loading layer d1b690ac41a7 513B / 513B 0.7s done
#29 loading layer a85ba680dedd 318B / 318B 0.6s done
#29 loading layer 7e4618ac3cb0 297B / 297B 0.5s done
#29 loading layer 43922422e132 4.00kB / 4.00kB 0.5s done
#29 DONE 82.4s

#28 exporting to docker image format
#28 sending tarball 147.4s done
#28 DONE 151.9s

#30 exporting cache to client directory
#30 preparing build cache for export
#30 writing layer sha256:0023eecf78ab7134b1dd4aba34e20134fe1a5e0827f3a2a65dead15239c056dd
#30 writing layer sha256:0023eecf78ab7134b1dd4aba34e20134fe1a5e0827f3a2a65dead15239c056dd 0.0s done
#30 writing layer sha256:014cff740c9ec6e9a30d0b859219a700ae880eb385d62095d348f5ea136d6015 done
#30 writing layer sha256:0487800842442c7a031a39e1e1857bc6dae4b4f7e5daf3d625f7a8a4833fb364 done
#30 writing layer sha256:06c6aee94862daf0603783db4e1de6f8524b30ac9fbe0374ab3f1d85b2f76f7f done
#30 writing layer sha256:0a1756432df4a4350712d8ae5c003f1526bd2180800b3ae6301cfc9ccf370254 done
#30 writing layer sha256:0a77dcbd0e648ddc4f8e5230ade8fdb781d99e24fa4f13ca96a360c7f7e6751f done
#30 writing layer sha256:0ec682bf99715a9f88631226f3749e2271b8b9f254528ef61f65ed829984821c done
#30 writing layer sha256:1c5c3aa9c2c8bfd1b9eb36248f5b6d67b3db73ef43440f9dd897615771974b39 done
#30 writing layer sha256:1f73278b7f17492ce1a8b28b139d54596961596d6790dc20046fa6d5909f3e9c done
#30 writing layer sha256:20d331454f5fb557f2692dfbdbe092c718fd2cb55d5db9d661b62228dacca5c2 done
#30 writing layer sha256:238f69a43816e481f0295995fcf5fe74d59facf0f9f99734c8d0a2fb140630e0 done
#30 writing layer sha256:2ad84487f9d4d31cd1e0a92697a5447dd241935253d036b272ef16d31620c1e7 done
#30 writing layer sha256:2f65750928993b5b31fe572d9e085b53853c5a344feeb0e8615898e285a8c256 done
#30 writing layer sha256:3777c6498f08c0400339c243e827d465075b7296eb2526e38d9b01c84f8764d8 done
#30 writing layer sha256:39d418046e5154e0c5c7e83ba5a4cabbca254facefc9cb7b3f1bc1a6cf51ade3 done
#30 writing layer sha256:3e3e04011ebdba380ab129f0ee390626cb2a600623815ca756340c18bedb9517 done
#30 writing layer sha256:42619ce4a0c9e54cfd0ee41a8e5f27d58b3f51becabd1ac6de725fbe6c42b14a done
#30 writing layer sha256:49bdc9abf8a437ccff67cc11490ba52c976577992909856a86be872a34d3b950 done
#30 writing layer sha256:4b691ba9f48b41eaa0c754feba8366f1c030464fcbc55eeffa6c86675990933a done
#30 writing layer sha256:4d04a8db404f16c2704fa10739cb6745a0187713a21a6ef0deb34b48629b54c1 done
#30 writing layer sha256:4f4fb700ef54461cfa02571ae0db9a0dc1e0cdb5577484a6d75e68dc38e8acc1 done
#30 writing layer sha256:542bc8c8d18fbc95e6794122c3593a4a693f8ab6dda4460406f4d7b1ae64a2bc done
#30 writing layer sha256:564f81ac5635380cf724ba7ab6fb8f4d3ff9a308a8c63c2ed585363b78804d5b
#30 writing layer sha256:564f81ac5635380cf724ba7ab6fb8f4d3ff9a308a8c63c2ed585363b78804d5b 0.4s done
#30 writing layer sha256:57f244836ad318f9bbb3b29856ae1a5b31038bfbb9b43d2466d51c199eb55041
#30 writing layer sha256:57f244836ad318f9bbb3b29856ae1a5b31038bfbb9b43d2466d51c199eb55041 done
#30 writing layer sha256:5b5b131e0f20db4cb8e568b623a95f8fc16ed1c6b322a9366df70b59a881f24f done
#30 writing layer sha256:5b90d17b5048adcadefd0b1e4dba9a99247a8827a887e1ca042df375c85b518d done
#30 writing layer sha256:62452179df7c18e292f141d4aec29e6aba9ff8270c893731169fc6f41dc07631 done
#30 writing layer sha256:6630c387f5f2115bca2e646fd0c2f64e1f3d5431c2e050abe607633883eda230 done
#30 writing layer sha256:6661e0146e77a8bcb03edbfda95bf7780c8bb4c4f98bc03a398c88f4b2403d12 done
#30 writing layer sha256:717ebf8c9c66ae393ad01e50dbac4413d7b026b9c97d4d348b22ad17052a1a35 done
#30 writing layer sha256:773c6815e5e7d6855a62f8c5e2fabce3d939ded36c5420f15b54dd7908cdbcfa done
#30 writing layer sha256:7852b73ea931e3a8d3287ee7ef3cf4bad068e44f046583bfc2b81336fb299284 done
#30 writing layer sha256:7f8ec130348bcdac81c295e37fe82b4a6e5e9a3ca980a6343809c561020d82d7 done
#30 writing layer sha256:80885adcad6b5d021bb9f68b6c952018085bb4ce72011bdc0cf7fe8178b5960b done
#30 writing layer sha256:81222fcc1cc074d3cda4ae4a57ce0376c275a9ba3ef167c9e0715489c4e63593 0.0s done
#30 writing layer sha256:82a3436133b2b17bb407c7fe488932aa0ca55411f23ab55c34a6134b287c6a27 done
#30 writing layer sha256:8371d15eb4d69b1d98174dd098b8ddd5c4f19ec6f8d8b67e72dfa9891dc454b4 done
#30 writing layer sha256:85713f9b166b5add777c524ee807f6265d88b967cbeb9f961d6b09bf220c9a65 done
#30 writing layer sha256:8fe00505006a09966e763918147ef6ed55bb6695b26e4940c780ee430dc5da8e done
#30 writing layer sha256:90eae6faa5cc5ba62f12c25915cdfb1a7a51abfba0d05cb5818c3f908f4e345f done
#30 writing layer sha256:9205d97d9d3e906698bcc6c42d45727c2fa6ec2622abf953d46778c3b8c78edc done
#30 writing layer sha256:993369dbcc13162a6654d2a3e990b8d8b5f37963564d25710e12764337261ae3 done
#30 writing layer sha256:99e42a4adebadb39bf55bf94bbd9fb8034230ee19b6b0a42e6ff96f2e7794f30 done
#30 writing layer sha256:9ac855545fa90ed2bf3b388fdff9ef06ac9427b0c0fca07c9e59161983d8827e done
#30 writing layer sha256:9d19ee268e0d7bcf6716e6658ee1b0384a71d6f2f9aa1ae2085610cf7c7b316f done
#30 writing layer sha256:9fafbd4203c4fefe007a462e0d2cd4c1c7c41db2cfdc58d212279e1b9b4b230c done
#30 writing layer sha256:a1748eee9d376f97bd19225ba61dfada9986f063f4fc429e435f157abb629fc6 done
#30 writing layer sha256:a251fe5ae6c6d2d5034e4ca88b5dfe5d4827ff90b18e9b143a073232a32bb18d done
#30 writing layer sha256:a68f4e0ec09ec3b78cb4cf8e4511d658e34e7b6f676d7806ad9703194ff17604 done
#30 writing layer sha256:a8e4decc8f7289623b8fd7b9ba1ca555b5a755ebdbf81328d68209f148d9e602 done
#30 writing layer sha256:acdd7441f23e148bb954e879221b72454121a7bba702612df91c871ef14129a1
#30 writing layer sha256:acdd7441f23e148bb954e879221b72454121a7bba702612df91c871ef14129a1 1.3s done
#30 writing layer sha256:afde1c269453ce68a0f2b54c1ba8c5ecddeb18a19e5618a4acdef1f0fe3921af
#30 writing layer sha256:afde1c269453ce68a0f2b54c1ba8c5ecddeb18a19e5618a4acdef1f0fe3921af done
#30 writing layer sha256:b406feb20a37b8c87ef4f5ef814039e3adc90473d50c366b7d9bb6ded4e94a2e done
#30 writing layer sha256:b48a5fafcaba74eb5d7e7665601509e2889285b50a04b5b639a23f8adc818157 done
#30 writing layer sha256:b9f7221ef56856ac3291be12159de2576b44cd2ab53493532f7c40e33b89106c done
#30 writing layer sha256:ba9f7c75e4dd7942b944679995365aab766d3677da2e69e1d74472f471a484dd done
#30 writing layer sha256:bdc13166216ae226fa6976f9ce91f4f259d43972f1e0a9b723e436919534b2f4 done
#30 writing layer sha256:c815f0be64eded102822d81e029bd23b0d8d9a0fbfeb492ec0b4b0bc4ee777bf done
#30 writing layer sha256:c98533d2908f36a5e9b52faae83809b3b6865b50e90e2817308acfc64cd3655f done
#30 writing layer sha256:d577841fd502ec678ac975415c7c08cc25663bc74b610b82dfbc012f52547f4b done
#30 writing layer sha256:d7da5c5e9a40c476c4b3188a845e3276dedfd752e015ea5113df5af64d4d43f7 done
#30 writing layer sha256:db20521a869adda8244cb64b783c65e1a911efaae0e73ae00e4a34ea6213d6ce done
#30 writing layer sha256:df4fd0ac710d7af949afbc6d25b5b4daf3f0596dabf3dec36fa7ca8fa6e1d049 done
#30 writing layer sha256:e1b6cb9ccb6b87a9b02f2d1913a5886076b6ef31ff1417fd63257b0d118e13e9 0.0s done
#30 writing layer sha256:e291ddecfbe16b95ee9e90b5e90b1a3d0cfd53dc5e720d6b0f3d28e4a47cf5ac done
#30 writing layer sha256:e8acb678f16bc0c369d5cf9c184f2d3a1c773986816526e5e3e9c0354f7e757f done
#30 writing layer sha256:e9225f7ab6606813ec9acba98a064826ebfd6713a9645a58cd068538af1ecddb done
#30 writing layer sha256:f249faf9663a96b0911a903f8803b11a553c59b698013fb8343492fefdaaea90 done
#30 writing layer sha256:f608e2fbff86e98627b7e462057e7d2416522096d73fe4664b82fe6ce8a4047d done
#30 writing layer sha256:f65d191416580d6c38e3d95eee12377b75a4df548be1492618ce2a8c3c41b99e done
#30 writing layer sha256:f7ff8f11209b473ea771d9abe10f41a9a65716da379f39ea47ddbae875701e0f 0.0s done
#30 writing layer sha256:f98f3676b44915df64d6115f562f826117cd134942616876d0d7c7d79c00ad0e 0.0s done
#30 writing config sha256:98d05c4f7922b70a3b4fb0ca92707228e91ce8bab93500fdcc0c31b1b0b64130 0.0s done
#30 preparing build cache for export 2.5s done
#30 writing cache manifest sha256:045b1d7a7e988bbb6957ed94aa829d8e4ce6fb0c09c284a2b102d385595e15d3 0.0s done
#30 DONE 2.5s
[2024-04-23 17:11:47,683] [INFO] (packager) - Build Summary:

Platform: x64-workstation/dgpu
    Status:     Succeeded
    Docker Tag: mednist_app-x64-workstation-dgpu-linux-amd64:1.0
    Tarball:    None

Note

Building a MONAI Application Package (Docker image) can take time. Use -l DEBUG option if you want to see the progress.

We can see that the Docker image is created.

!docker image ls | grep {tag_prefix}
mednist_app-x64-workstation-dgpu-linux-amd64                                              1.0                 63c2bd27a223   2 minutes ago    17.7GB

Executing packaged app locally

We can choose to display and export the MAP manifests, but in this example, we will just run the MAP through MONAI Application Runner.

# Clear the output folder and run the MAP. The input is expected to be a folder.
!rm -rf $HOLOSCAN_OUTPUT_PATH
!monai-deploy run -i$HOLOSCAN_INPUT_PATH -o $HOLOSCAN_OUTPUT_PATH mednist_app-x64-workstation-dgpu-linux-amd64:1.0
[2024-04-23 17:11:48,890] [INFO] (runner) - Checking dependencies...
[2024-04-23 17:11:48,890] [INFO] (runner) - --> Verifying if "docker" is installed...

[2024-04-23 17:11:48,891] [INFO] (runner) - --> Verifying if "docker-buildx" is installed...

[2024-04-23 17:11:48,891] [INFO] (runner) - --> Verifying if "mednist_app-x64-workstation-dgpu-linux-amd64:1.0" is available...

[2024-04-23 17:11:48,968] [INFO] (runner) - Reading HAP/MAP manifest...
Preparing to copy...?25lCopying from container - 0B?25hSuccessfully copied 2.56kB to /tmp/tmpgkozmakd/app.json
Preparing to copy...?25lCopying from container - 0B?25hSuccessfully copied 2.05kB to /tmp/tmpgkozmakd/pkg.json
[2024-04-23 17:11:51,690] [INFO] (runner) - --> Verifying if "nvidia-ctk" is installed...

[2024-04-23 17:11:51,690] [INFO] (runner) - --> Verifying "nvidia-ctk" version...

[2024-04-23 17:11:52,019] [INFO] (common) - Launching container (29c362c90847) using image 'mednist_app-x64-workstation-dgpu-linux-amd64:1.0'...
    container name:      competent_aryabhata
    host name:           mingq-dt
    network:             host
    user:                1000:1000
    ulimits:             memlock=-1:-1, stack=67108864:67108864
    cap_add:             CAP_SYS_PTRACE
    ipc mode:            host
    shared memory size:  67108864
    devices:             
    group_add:           44
2024-04-24 00:11:52 [INFO] Launching application python3 /opt/holoscan/app/mednist_classifier_monaideploy.py ...

[info] [app_driver.cpp:1161] Launching the driver/health checking service

[info] [gxf_executor.cpp:247] Creating context

[info] [server.cpp:87] Health checking server listening on 0.0.0.0:8777

[info] [gxf_executor.cpp:1672] Loading extensions from configs...

[info] [gxf_executor.cpp:1842] Activating Graph...

[info] [gxf_executor.cpp:1874] Running Graph...

[info] [gxf_executor.cpp:1876] Waiting for completion...

2024-04-24 00:11:55.786 INFO  gxf/std/greedy_scheduler.cpp@191: Scheduling 3 entities

/home/holoscan/.local/lib/python3.10/site-packages/monai/data/meta_tensor.py:116: UserWarning: The given NumPy array is not writable, and PyTorch does not support non-writable tensors. This means writing to this tensor will result in undefined behavior. You may want to copy the array to protect its data or make it writable before converting it to a tensor. This type of warning will be suppressed for the rest of this program. (Triggered internally at ../torch/csrc/utils/tensor_numpy.cpp:206.)

  return torch.as_tensor(x, *args, **_kwargs).as_subclass(cls)

/home/holoscan/.local/lib/python3.10/site-packages/pydicom/valuerep.py:443: UserWarning: Invalid value for VR UI: 'xyz'. Please see <https://dicom.nema.org/medical/dicom/current/output/html/part05.html#table_6.2-1> for allowed values for each VR.

  warnings.warn(msg)

2024-04-24 00:11:57.183 INFO  gxf/std/greedy_scheduler.cpp@372: Scheduler stopped: Some entities are waiting for execution, but there are no periodic or async entities to get out of the deadlock.

2024-04-24 00:11:57.184 INFO  gxf/std/greedy_scheduler.cpp@401: Scheduler finished.

[info] [gxf_executor.cpp:1879] Deactivating Graph...

[info] [gxf_executor.cpp:1887] Graph execution finished.

[info] [gxf_executor.cpp:275] Destroying context

AbdomenCT

[2024-04-23 17:11:58,233] [INFO] (common) - Container 'competent_aryabhata'(29c362c90847) exited.
!cat $HOLOSCAN_OUTPUT_PATH/output.json
"AbdomenCT"

Note: Please execute the following script once the exercise is done.

# Remove data files which is in the temporary folder
if directory is None:
    shutil.rmtree(root_dir)