Skip to content

Integration with SCT

Naga Karthik edited this page Oct 5, 2023 · 1 revision

Integration of MONAI/nnUNet models into the SpinalCordToolbox (SCT)

This document describes the process of how the deep learning (DL) models trained with MONAI or nnUNet are integrated into SCT.

Step 1 (on the monai/nnUNet side)

TODO ....

Step 2 (on the SCT side)

  • In order for this model to be used by SCT users, an entry in the same format as described in this file has to be made. This has to be done for both MODELS and TASKS dicitionaries. For example, an entry in the MODELS dict looks like (note how in the url the zipped package in Step 1 is linked):
"model_seg_ms_lesion_mp2rage": {
    "url": [
        "https://github.com/ivadomed/model_seg_ms_mp2rage/releases/download/r20211223/model_seg_ms_lesion_mp2rage.zip"
    ],
    "description": "Segmentation of multiple sclerosis lesions on cropped MP2RAGE spinal cord data. To crop the "
                   "data you can first segment the spinal cord using the model 'model_seg_ms_sc_mp2rage' and "
                   "then crop the MP2RAGE image using 'sct_crop_image -i IMAGE -m IMAGE_seg'",
    "contrasts": ["mp2rage"],
    "default": False,
},

  • NOTE: These changes have to first be approved by a SCT developer through a Pull Request (PR) in the SCT's repository.
  • Once the PR has been approved:
    • All the available models can be viewed using the following command sct_deepseg -list-tasks.
    • The (new) model can be downloaded and extracted using sct_deepseg -install-task <model-name>
    • Then, inference can be run using this model from this command sct_deepseg -i img.nii.gz -task <task_name>. Note, the task name is the same name that is in the TASKS dict in the spinalcordtoolbox/deepseg/models.py file.

Step 3 (behind-the-scenes)

TODO: update this to monai's and nnUNet's inference calls

Whenever we use sct_deepseg, it internally calls the ivadomed.inference.segment_volume function that essentially uses the downloaded (trained) model and segments the input image based on the given task.

Summary

In conclusion, integration into SCT is just:

  1. Hosting a model online, and
  2. Adding it to sct_deepseg, from which it can then be downloaded and used.
Clone this wiki locally