### Setup Development Environment Source: https://github.com/project-monai/monai-deploy-app-sdk/blob/main/CONTRIBUTING.md Execute this command to set up the development environment and install necessary packages. Use '-h' for help. ```bash ./run setup # '-h' for help ``` -------------------------------- ### Install Dependencies for Simple Imaging App Source: https://github.com/project-monai/monai-deploy-app-sdk/blob/main/README.md Installs additional Python dependencies required for the simple_imaging_app example. ```bash pip install matplotlib Pillow scikit-image ``` -------------------------------- ### Run Application with Options: Skip Install and No GPU Source: https://github.com/project-monai/monai-deploy-app-sdk/blob/main/tools/pipeline-generator/README.md Examples of running a generated application while skipping dependency installation if already set up, and disabling GPU support. ```bash # Skip dependency installation (if already installed) uv run pg run my_app --input test_data --output results --skip-install # Run without GPU uv run pg run my_app --input test_data --output results --no-gpu ``` -------------------------------- ### LoadPILOperator Setup Method Source: https://github.com/project-monai/monai-deploy-app-sdk/blob/main/notebooks/tutorials/02_mednist_app.ipynb The setup method configures the output port for the operator, specifying the name under which the image will be emitted. ```python from monai.deploy.core import OperatorSpec # Inside the setup method of LoadPILOperator: # ... (previous code) def setup(self, spec: OperatorSpec): """Set up the named input and output port(s)""" spec.output(self.output_name_image) ``` -------------------------------- ### Install Nuance PIN AI Service Libraries on Host Source: https://github.com/project-monai/monai-deploy-app-sdk/blob/main/platforms/nuance_pin/README.md This snippet shows how to set up a virtual environment, install the Nuance PIN AI Service libraries, and install other required libraries from requirements.txt to run the service directly on the host. ```bash # create a virtual environment and activate it python3 -m venv /opt/venv . /opt/venv/bin/activate # install Nuance Ai Service pip install ai_service--py3-none-any.whl # install requirements pip install -r requirements.txt ``` -------------------------------- ### Example: Packaging a MONAI Application Source: https://github.com/project-monai/monai-deploy-app-sdk/wiki/Packaging-app This example demonstrates packaging a MONAI SDK application located at './spleen_segmentation_app' and tagging the resulting Docker image as 'monaispleen:latest'. ```bash $ monai-deploy package ./spleen_segmentation_app -t monaispleen:latest Building MONAI Application Package... Successfully built monaispleen:latest ``` -------------------------------- ### Run Generated Application with Input/Output Source: https://github.com/project-monai/monai-deploy-app-sdk/blob/main/tools/pipeline-generator/README.md Executes a generated MONAI Deploy application, specifying input data and an output directory for results. The tool handles environment setup and dependency installation. ```bash uv run pg run my_app --input /path/to/input --output /path/to/output ``` -------------------------------- ### List Example App Directory Source: https://github.com/project-monai/monai-deploy-app-sdk/blob/main/notebooks/tutorials/02_mednist_app-prebuilt.ipynb Lists the contents of the mednist_classifier_monaideploy example application directory within the cloned repository. ```python !ls source/examples/apps/mednist_classifier_monaideploy/ ``` -------------------------------- ### Clone Project, Install SDK, and Run App Locally Source: https://github.com/project-monai/monai-deploy-app-sdk/blob/main/docs/source/getting_started/tutorials/mednist_app.md Clone the MONAI Deploy App SDK repository, install the SDK, download and extract data, install app requirements, and run the MedNIST classifier app locally using environment variables. ```bash # Clone the github project (the latest version of the main branch only) git clone --branch main --depth 1 https://github.com/Project-MONAI/monai-deploy-app-sdk.git cd monai-deploy-app-sdk # Install monai-deploy-app-sdk package pip install monai-deploy-app-sdk # Download/Extract mednist_classifier_data.zip from https://drive.google.com/file/d/1yJ4P-xMNEfN6lIOq_u6x1eMAq1_MJu-E/view?usp=sharing # After having downloaded mednist_classifier_data.zip from the web browser or using gdown unzip -o mednist_classifier_data.zip # Install necessary packages required by the app pip install -r examples/apps/mednist_classifier_monaideploy/requirements.txt # Local execution of the app using environment variables for input, output, and model paths # instead of command line options, `-i input/AbdomenCT_007000.jpeg -o output -m classifier.zip` export HOLOSCAN_INPUT_PATH="input/AbdomenCT_007000.jpeg" export HOLOSCAN_MODEL_PATH="classifier.zip" export HOLOSCAN_OUTPUT_PATH="output" python examples/apps/mednist_classifier_monaideploy/mednist_classifier_monaideploy.py # See the classification result cat output/output.json ``` -------------------------------- ### Install MONAI Deploy App SDK Source: https://github.com/project-monai/monai-deploy-app-sdk/blob/main/notebooks/tutorials/02_mednist_app-prebuilt.ipynb Installs the monai-deploy-app-sdk package using pip. ```python !pip install monai-deploy-app-sdk ``` -------------------------------- ### Clone Project, Install SDK, and Prepare Model Data Source: https://github.com/project-monai/monai-deploy-app-sdk/blob/main/docs/source/getting_started/tutorials/segmentation_app.md Clone the monai-deploy-app-sdk repository, install the SDK, download and prepare the model and test data, and set up the necessary directory structure. ```bash # Clone the github project (the latest version of main branch only) git clone --branch main --depth 1 https://github.com/Project-MONAI/monai-deploy-app-sdk.git cd monai-deploy-app-sdk # Install monai-deploy-app-sdk package pip install --upgrade monai-deploy-app-sdk # Download the zip file containing both the model and test data. # After downloading it using gdown, unzip the zip file saved by gdown and # copy the model file into a folder structure that is required by CLI Packager rm -rf dcm unzip -o ai_spleen_seg_bundle_data.zip rm -rf spleen_model && mkdir -p spleen_model && mv model.ts spleen_model && ls spleen_model ``` -------------------------------- ### Install Dependencies Source: https://github.com/project-monai/monai-deploy-app-sdk/blob/main/platforms/aidoc/README.md Installs the necessary Python packages for the RESTful application. Ensure you are in the correct directory and have a virtual environment activated. ```bash pip install -r restful_app/requirements.txt ``` -------------------------------- ### Install Pipeline Generator with uv Source: https://github.com/project-monai/monai-deploy-app-sdk/blob/main/tools/pipeline-generator/README.md Clone the repository and install the pipeline generator using uv, which manages virtual environments automatically. ```bash cd tools/pipeline-generator/ uv pip install -e ".[dev]" ``` -------------------------------- ### Example of Packaging a MONAI Deploy Application Source: https://github.com/project-monai/monai-deploy-app-sdk/blob/main/docs/source/developing_with_sdk/packaging_app.md This example demonstrates how to package a MONAI Deploy application located at `./my_app` into a Docker image tagged `my_app:latest`. It includes specifying the configuration file, tag, model path, and platform. ```bash $ monai-deploy package ./my_app -c --config ./my_app/app.yaml -t my_app:latest --models ./model.ts --platform x86_64 Building MONAI Application Package... Successfully built my_app:latest ``` -------------------------------- ### Install MONAI and Dependencies Source: https://github.com/project-monai/monai-deploy-app-sdk/blob/main/notebooks/tutorials/05_multi_model_app.ipynb Installs MONAI, PyTorch, NumPy, nibabel, pydicom, highdicom, and SimpleITK. Ensures the MONAI Deploy App SDK is also installed or upgraded. ```python # Install MONAI and other necessary image processing packages for the application !python -c "import monai" || pip install --upgrade -q "monai<=1.5.0" !python -c "import torch" || pip install -q "torch>=1.12.0" !python -c "import numpy" || pip install -q "numpy>=1.21" !python -c "import nibabel" || pip install -q "nibabel>=3.2.1" !python -c "import pydicom" || pip install -q "pydicom>=1.4.2" !python -c "import highdicom" || pip install -q "highdicom>=0.18.2" !python -c "import SimpleITK" || pip install -q "SimpleITK>=2.0.0" # Install MONAI Deploy App SDK package !python -c "import monai.deploy" || pip install -q "monai-deploy-app-sdk" ``` -------------------------------- ### Clone Project, Install SDK, and Prepare Data Source: https://github.com/project-monai/monai-deploy-app-sdk/blob/main/docs/source/getting_started/tutorials/monai_bundle_app.md Clone the MONAI Deploy App SDK repository, install the SDK, and prepare the application data by downloading and extracting a zip file containing the model and test data. ```bash # Clone the github project (the latest version of main branch only) git clone --branch main --depth 1 https://github.com/Project-MONAI/monai-deploy-app-sdk.git cd monai-deploy-app-sdk # Install monai-deploy-app-sdk package pip install --upgrade monai-deploy-app-sdk # Download/Extract ai_spleen_bundle_data zip file from https://drive.google.com/file/d/1cJq0iQh_yzYIxVElSlVa141aEmHZADJh/view?usp=sharing # Download the zip file containing both the model and test data. # After downloading it using gdown, unzip the zip file saved by gdown and # copy the model file into a folder structure that is required by CLI Packager rm -rf dcm unzip -o ai_spleen_seg_bundle_data.zip rm -rf spleen_model && mkdir -p spleen_model && mv model.ts spleen_model && ls spleen_model ``` -------------------------------- ### Install MONAI Deploy App SDK and Dependencies Source: https://github.com/project-monai/monai-deploy-app-sdk/blob/main/docs/source/getting_started/tutorials/simple_app.md Installs the MONAI Deploy App SDK package and other required Python libraries for the simple imaging app. ```bash pip install monai-deploy-app-sdk pip install scikit-image, setuptools, Pillow, matplotlib ``` -------------------------------- ### Status Response Example Source: https://github.com/project-monai/monai-deploy-app-sdk/blob/main/platforms/aidoc/README.md Example of a successful response when checking the processor status. Can be 'IDLE' or 'PROCESSING'. ```json { "status": "IDLE" } ``` -------------------------------- ### Install MONAI Deploy App SDK Source: https://github.com/project-monai/monai-deploy-app-sdk/blob/main/README.md Installs the latest release of the MONAI Deploy App SDK using pip. ```bash pip install monai-deploy-app-sdk ``` -------------------------------- ### Clone Repository and Install SDK Source: https://github.com/project-monai/monai-deploy-app-sdk/blob/main/docs/source/getting_started/tutorials/multi_model_app.md Clones the latest version of the monai-deploy-app-sdk from GitHub and installs the SDK package. Ensure you are in the correct directory after cloning. ```bash git clone --branch main --depth 1 https://github.com/Project-MONAI/monai-deploy-app-sdk.git cd monai-deploy-app-sdk pip install --upgrade monai-deploy-app-sdk ``` -------------------------------- ### Example: Convert Dataset 4 to MONAI Bundle Source: https://github.com/project-monai/monai-deploy-app-sdk/blob/main/examples/apps/cchmc_nnunet_fifteen_ckpt_app/README.md This example demonstrates converting a specific nnUNet dataset (ID 4) and saving the resulting MONAI bundle to the current directory. ```bash python convert_nnunet_ckpts.py \ --dataset_name_or_id 4 \ --MAP_root "." \ --nnUNet_results "/path/to/nnunet/models" ``` -------------------------------- ### Example Pipeline Generator Configuration Source: https://github.com/project-monai/monai-deploy-app-sdk/blob/main/tools/pipeline-generator/README.md An example YAML configuration file structure for the Pipeline Generator, defining model sources. ```yaml model_list: - name: MONAI url: https://huggingface.co/api/models?owner=MONAI&limit=100 - name: Tested Models url: https://huggingface.co/api/models?search=monai-deploy-tested&limit=100 ``` -------------------------------- ### Run the Web Application Source: https://github.com/project-monai/monai-deploy-app-sdk/blob/main/platforms/aidoc/README.md Starts the RESTful application. The application will be accessible at http://127.0.0.1:5000. ```bash python restful_app/app.py ``` -------------------------------- ### Example .env file for MongoDB Configuration Source: https://github.com/project-monai/monai-deploy-app-sdk/blob/main/examples/apps/cchmc_ped_abd_ct_seg_app/README.md This snippet shows an example .env file format for configuring MongoDB credentials and connection details, used by the MongoDBWriterOperator in MONAI Deploy Express. ```dotenv MONGODB_USERNAME=root MONGODB_PASSWORD=rootpassword MONGODB_PORT=27017 MONGODB_IP_DOCKER=172.17.0.1 # default Docker bridge network IP ``` -------------------------------- ### Triton Model Configuration Example Source: https://github.com/project-monai/monai-deploy-app-sdk/blob/main/examples/apps/ai_remote_infer_app/README.md This is an example of a Triton model configuration file (config.pbtxt). It defines model metadata such as input/output dimensions, data types, and batching configuration, which is used by the client to understand the model's interface for remote inference. ```protobuf name: "spleen_ct" platform: "pytorch_libtorch" max_batch_size: 1 input [ { name: "input" data_type: TYPE_FP32 dims: [ 1, 96, 96, 96 ] } ] output [ { name: "output" data_type: TYPE_FP32 dims: [ 2, 96, 96, 96 ] } ] instance_group [ { count: 1 kind: KIND_GPU gpus: [ 0 ] } ] } ``` -------------------------------- ### Install MONAI Core and Dependencies Source: https://github.com/project-monai/monai-deploy-app-sdk/blob/main/notebooks/tutorials/02_mednist_app.ipynb Installs necessary packages for MONAI Core, including optional dependencies like Pillow, TQDM, Ignite, gdown, pydicom, and highdicom. This ensures all required libraries are available for the tutorial. ```python # 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" ``` -------------------------------- ### Prepare Input, Output, and Model Directories Source: https://github.com/project-monai/monai-deploy-app-sdk/blob/main/notebooks/tutorials/02_mednist_app.ipynb Sets up input, output, and model directories, copies a test input image and the trained model into their respective folders, and lists the contents to verify. ```bash 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 packaging, 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 ``` -------------------------------- ### Run Documentation Development Server Source: https://github.com/project-monai/monai-deploy-app-sdk/blob/main/CONTRIBUTING.md Launch a live server to build and test HTML documentation locally in runtime. ```bash ./run gen_docs_dev # '-h' for help ``` -------------------------------- ### Example __main__.py for Application Entrypoint Source: https://github.com/project-monai/monai-deploy-app-sdk/blob/main/docs/source/developing_with_sdk/packaging_app.md This Python script serves as the entrypoint for a MONAI Deploy application when packaged. It assumes your main application class is defined in `app.py`. ```python # Assuming that the class `App` (that inherits Application) is defined in `app.py`. from app import App if __name__ == "__main__": App().run() ``` -------------------------------- ### Run Generated MONAI Deploy Application CLI Command Source: https://github.com/project-monai/monai-deploy-app-sdk/blob/main/tools/pipeline-generator/docs/design.md This command executes a previously generated MONAI Deploy application. It handles environment setup, dependency installation, and application execution. ```bash pg run path-to-generated-app --input test-data-dir --output result-dir ``` -------------------------------- ### Build Documentation Source: https://github.com/project-monai/monai-deploy-app-sdk/blob/main/CONTRIBUTING.md Build HTML documentation for the project. Use '-h' for help. ```bash ./run gen_docs # '-h' for help ``` -------------------------------- ### Install MONAI Deploy App SDK Source: https://github.com/project-monai/monai-deploy-app-sdk/blob/main/notebooks/tutorials/01_simple_app.ipynb Installs the MONAI Deploy App SDK package if it's not already installed. This is a core dependency for building applications with the SDK. ```python # Install MONAI Deploy App SDK package !python -c "import monai.deploy" || pip install -q "monai-deploy-app-sdk" ``` -------------------------------- ### Install MONAI and Dependencies Source: https://github.com/project-monai/monai-deploy-app-sdk/blob/main/notebooks/tutorials/04_monai_bundle_app.ipynb Installs MONAI, PyTorch, NumPy, and other essential libraries for medical image processing and application development. A kernel restart may be required after installation. ```python # Install MONAI and other necessary image processing packages for the application !python -c "import monai" || pip install --upgrade -q "monai<=1.5.0" !python -c "import torch" || pip install -q "torch>=1.12.0" !python -c "import numpy" || pip install -q "numpy>=1.21.6" !python -c "import nibabel" || pip install -q "nibabel>=3.2.1" !python -c "import pydicom" || pip install -q "pydicom>=2.3.0" !python -c "import highdicom" || pip install -q "highdicom>=0.18.2" !python -c "import SimpleITK" || pip install -q "SimpleITK>=2.0.0" !python -c "import skimage" || pip install -q "scikit-image>=0.17.2" !python -c "import stl" || pip install -q "numpy-stl>=2.12.0" !python -c "import trimesh" || pip install -q "trimesh>=3.8.11" # Install MONAI Deploy App SDK package !python -c "import holoscan" || pip install --upgrade -q "holoscan>=0.6.0" !python -c "import monai.deploy" || pip install -q "monai-deploy-app-sdk" ``` -------------------------------- ### Build and Start Nuance PIN Container Source: https://github.com/project-monai/monai-deploy-app-sdk/blob/main/platforms/nuance_pin/README.md Build the Docker image and start the container that runs the MONAI app as a Nuance service. This command also starts the service. ```bash docker-compose up --build ``` -------------------------------- ### Complete Workflow Example for Pipeline Generator Source: https://github.com/project-monai/monai-deploy-app-sdk/blob/main/tools/pipeline-generator/README.md Demonstrates the typical workflow: listing models, generating an application from a specific model, and then running the generated application with input data. ```bash # 1. List available models uv run pg list # 2. Generate an application from a model uv run pg gen MONAI/spleen_ct_segmentation --output my_app # 3. Run the application uv run pg run my_app --input /path/to/test/data --output ./results ``` -------------------------------- ### Install MONAI and Dependencies Source: https://github.com/project-monai/monai-deploy-app-sdk/blob/main/notebooks/tutorials/03_segmentation_app.ipynb Installs MONAI, PyTorch, NumPy, Nibabel, PyDicom, Highdicom, and SimpleITK. Ensure these packages are up-to-date for application compatibility. A kernel restart may be required after installation. ```python # Install MONAI and other necessary image processing packages for the application !python -c "import monai" || pip install --upgrade -q "monai" !python -c "import torch" || pip install -q "torch>=1.10.2" !python -c "import numpy" || pip install -q "numpy>=1.21" !python -c "import nibabel" || pip install -q "nibabel>=3.2.1" !python -c "import pydicom" || pip install -q "pydicom>=1.4.2" !python -c "import highdicom" || pip install -q "highdicom>=0.18.2" !python -c "import SimpleITK" || pip install -q "SimpleITK>=2.0.0" # Install MONAI Deploy App SDK package !python -c "import monai.deploy" || pip install -q "monai-deploy-app-sdk" ``` -------------------------------- ### Instantiate and Run Application Source: https://github.com/project-monai/monai-deploy-app-sdk/blob/main/docs/source/developing_with_sdk/executing_app_locally.ipynb Instantiates the previously defined 'App' class and executes it using the 'run()' method. This is a common pattern for starting the application's execution flow. ```python app = App() app.run() ``` -------------------------------- ### Create Application Directory Source: https://github.com/project-monai/monai-deploy-app-sdk/blob/main/notebooks/tutorials/01_simple_app.ipynb Creates a directory for the simple imaging application. ```bash !mkdir -p simple_imaging_app ``` -------------------------------- ### Execute Application with Options Source: https://github.com/project-monai/monai-deploy-app-sdk/blob/main/notebooks/tutorials/01_simple_app.ipynb Executes the application from the command line, specifying input, output, and logging level. ```bash !rm -rf {output_path} !python simple_imaging_app -i {test_input_folder} -o {output_path} -l DEBUG ``` -------------------------------- ### Processing Started Response Source: https://github.com/project-monai/monai-deploy-app-sdk/blob/main/platforms/aidoc/README.md Confirms that a new processing job has been successfully started. Returned with a 202 ACCEPTED status code. ```http POST /process Content-Type: application/json { "input_folder": "/path/to/your/input/data", "output_folder": "/path/to/your/output/folder", "callback_url": "http://your-service.com/callback" } HTTP/1.1 202 ACCEPTED Content-Type: application/json { "message": "Processing started." } ``` -------------------------------- ### Example Signed-off-by Commit Message Source: https://github.com/project-monai/monai-deploy-app-sdk/blob/main/CONTRIBUTING.md This is an example of a commit message that includes the automatically appended 'Signed-off-by' line required by the DCO. ```text a new commit Signed-off-by: Your Name ``` -------------------------------- ### Initialize Network, Loss Function, and Optimizer Source: https://github.com/project-monai/monai-deploy-app-sdk/blob/main/notebooks/tutorials/02_mednist_app.ipynb Sets up the neural network (DenseNet121), loss function (CrossEntropyLoss), and optimizer (Adam) for training. It also determines the computation device (CUDA or CPU). ```python 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 ``` -------------------------------- ### Install Clara Viz Package Source: https://github.com/project-monai/monai-deploy-app-sdk/blob/main/notebooks/tutorials/03_segmentation_viz_app.ipynb Installs the Clara Viz package, which is used for visualization purposes within the application. This is crucial for visualizing segmentation results. ```python # Install Clara Viz package !python -c "import clara.viz" || pip install --upgrade -q "clara-viz" ``` -------------------------------- ### Configure Environment and Output Folder Source: https://github.com/project-monai/monai-deploy-app-sdk/blob/main/notebooks/tutorials/02_mednist_app.ipynb Sets up the necessary environment using pip packages and defines the output folder for results. Ensures the output directory exists. ```python # @md.env(pip_packages=["monai"]) 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) ``` -------------------------------- ### Install Necessary Image Processing Packages Source: https://github.com/project-monai/monai-deploy-app-sdk/blob/main/notebooks/tutorials/01_simple_app.ipynb Installs Pillow, scikit-image, and Matplotlib if they are not already present. These are required for image loading and processing within the application. ```python # Install necessary image loading/processing packages for the application !python -c "import PIL" || pip install -q "Pillow" !python -c "import skimage" || pip install -q "scikit-image" !python -c "import matplotlib" || pip install -q "matplotlib" %matplotlib inline ``` -------------------------------- ### Install and Run AiSvcTest Utility Source: https://github.com/project-monai/monai-deploy-app-sdk/blob/main/platforms/nuance_pin/README.md Installs the AiSvcTest utility using pip and then runs it with specified input, output, and service parameters to test a DICOM payload. ```bash . /opt/venv/bin/activate pip install AiSvcTest--py3-none-any.whl # create an output directory for the inference results mkdir -p ~/Downloads/dcm/out # run AiSvcTest with spleen dicom payload python -m AiSvcTest -i ~/Downloads/dcm -o ~/Downloads/dcm/out -s http://localhost:5000 -V 2 -k ``` -------------------------------- ### Setup and Run Supervised Trainer Source: https://github.com/project-monai/monai-deploy-app-sdk/blob/main/notebooks/tutorials/02_mednist_app.ipynb Configures and runs the supervised trainer with a custom batch preparation function and an event handler to print the loss at the end of each epoch. ```python 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() ``` -------------------------------- ### Run the Packaged App with Docker Source: https://github.com/project-monai/monai-deploy-app-sdk/blob/main/docs/source/getting_started/tutorials/multi_model_app.md Executes the previously packaged Docker image locally. It maps input and output directories and lists the contents of the output directory after execution. ```bash # Run the app with docker image and input file locally rm -rf output monai-deploy run multi_model_app-x64-workstation-dgpu-linux-amd64:latest -i dcm -o output ls -R output ``` -------------------------------- ### Define and Run a Simple MONAI Deploy Application Source: https://github.com/project-monai/monai-deploy-app-sdk/blob/main/notebooks/tutorials/01_simple_app.ipynb This snippet defines a basic MONAI Deploy application named 'simple_imaging_app'. It composes three operators (Sobel, Median, Gaussian) and defines the data flow between them. The application is configured using command-line arguments via `Application.init_app_context` and executed using `App().run()`. ```python # @resource(cpu=1) class App(Application): """This is a very basic application. This showcases the MONAI Deploy application framework. """ # App's name. ('App') if not specified. name = "simple_imaging_app" # App's description. if not specified. description = "This is a very simple application." # App's version. or '0.0.0' if not specified. version = "0.1.0" def compose(self): """This application has three operators. Each operator has a single input and a single output port. Each operator performs some kind of image processing function. """ # Use Commandline options over environment variables to init context. app_context = Application.init_app_context(self.argv) sample_data_path = Path(app_context.input_path) output_data_path = Path(app_context.output_path) logging.info(f"sample_data_path: {sample_data_path}") # Please note that the Application object, self, is passed as the first positional argument # and the others as kwargs. # Also note the CountCondition of 1 on the first operator, indicating to the application executor # to invoke this operator, hence the pipeline, only once. sobel_op = SobelOperator(self, CountCondition(self, 1), input_path=sample_data_path, name="sobel_op") median_op = MedianOperator(self, name="median_op") gaussian_op = GaussianOperator(self, output_folder=output_data_path, name="gaussian_op") self.add_flow( sobel_op, median_op, { ("out1", "in1"), }, ) self.add_flow( median_op, gaussian_op, { ( "out1", "in1", ) }, ) if __name__ == "__main__": logging.info(f"Begin {__name__}") App().run() logging.info(f"End {__name__}") ``` -------------------------------- ### Operator Input/Output Definition in setup() Source: https://github.com/project-monai/monai-deploy-app-sdk/blob/main/docs/source/release_notes/v1.0.0.md In version 1.0.0, Operator inputs and outputs must be defined within the setup() method of the class, replacing the previous decorator-based approach. ```python # Operator input(s) and output(s) now must be defined in the setup() method of this class ``` -------------------------------- ### Install Additional Packages Source: https://github.com/project-monai/monai-deploy-app-sdk/blob/main/notebooks/tutorials/02_mednist_app-prebuilt.ipynb Installs necessary packages for the MedNIST classifier app, including MONAI transforms, Pillow for image handling, and optionally pydicom and highdicom for DICOM support. ```python !pip install monai Pillow # for MONAI transforms and Pillow !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 ```