Using MONAI on UKB-RAP

Oliver G
Oliver G The helpers that keep the community running smoothly. UKB Community team Data Analyst
  • Updated

UK Biobank provides access to a rich and diverse set of imaging data, including brain, heart, and body scans. These datasets are available in formats such as NIfTI and DICOM, and more information can be found on the UK Biobank Imaging data home page.

To support the analysis of these medical images, the UK Biobank Research Analysis Platform (UKB-RAP) integrates MONAI Label, a powerful, open-source tool designed for AI-assisted medical image annotation and analysis. MONAI Label is part of the broader MONAI (Medical Open Network for AI) framework, which is built on PyTorch and tailored for healthcare imaging applications. More information can be found on the MONAI home page.

 

Within the UKB-RAP, MONAI Label is available as:

 

This integration enables researchers to interactively annotate, segment, and analyse the extensive UK Biobank imaging dataset using AI models.

This article provides a practical guide to using MONAI Label with 3D Slicer on the UKB RAP. It includes:

  • Example inputs and workflows
  • Instructions for launching analysis instances
  • Types of analyses that can be performed

These tools can be found in the tool library in your UKB-RAP project space. After logging into your UKB-RAP project, navigate to the Tools tab. Here, a list of available applications are listed, including MONAI Label. These tools can be launched directly and interactively from the platform.

3D Slicer with MONAI Label

The 3D Slicer with MONAI Label tool, the interface provides detailed information about the types of inputs required and their expected formats. This includes guidance on required input files like the structure and type: 

  • Image input - required
  • Label Input
  • Model Input - required 
  • Additional settings specific to the session.

The example in this article will use data from Field ID 20201 (Dixon technique for internal fat abdominal MRI images- DICOM format). 

Getting started - Inputs

The inputs for MONAI Label with 3D Slicer should be completed depending on your individual use case. 

Imaging files of interest can be loaded directly from your UKB-RAP project. These files are typically stored in the Bulk folder of your DNAnexus project. A manifest file listing the file IDs can help when working with a large number of files or when automating input selection with a cohort selection script.

Image Inputs

Note: Provide either:

  • Image or Image Archive Files to Populate the MONAI Studies Directory

    Or

  • Manifest File of Image or Image Archive Files to Populate the MONAI Studies Directory (see Appendix A for formatting instructions)
 

Paths to the Image Files within ZIP archives

UK Biobank provides image files within ZIP archives. The path to a ZIP-archived image file can be provided as a parameter. This will only work for image files that are compatible with 3D Slicer and MONAI Label. Notably, this input is not required for DICOM files.
 
For example, the T1_brain.nii.gz files from the pre-processed NIFTI images (e.g. Field 20252 - T1 structural brain images - NIFTI) can be loaded into the compute instance using the file path T1/T1_brain.nii.gz
 

Use DICOM Image File Format

UK Biobank provides DICOM image files in zip archives (e.g. Field 20201 - Neck-to-knee MRI). These images are compatible with 3D Slicer and MONAI label, and the Use DICOM "Image File Format" parameter should be set to true where all input images are DICOM format (.dcm). 

To begin with, using a mix of DICOM and images of other formats is not recommended.

 

Label Input

Editable label Files

The Original Label Files and Manifest File of Original Label Files parameters allow the user to include draft mask images that describe structures of the files included in the Image Inputs. Labels should have matching dimensions to the image they label (e.g., a 256 × 256 image should have a 256 × 256 label file). Notably, the draft mask files included here will be editable within the 3D Slicer with MONAI Label tool. See the Annotating Images section below for methods.

Note, provide only Original Label Files or Manifest File of Original Label Files.

Final Label Files

The Final Label Files and Manifest File of Final Label Files parameters allow the user to include mask images which will not be editable within the 3D Slicer with MONAI Label tool. These can subsequently be utilised for testing, validation, or additional training of models.

Note, provide only Final Label Files or Manifest File of Final Label Files.

 

Model Input

The following two fields are sufficient for starting all pre-trained models currently available from MONAI.

Name(s) of Pre-trained Model(s) - Required

The name of pre-trained models must exactly match one of the MONAI Label pre-trained models. This name must match one of the following:

  • A model listed in the MONAI Label Radiology App pre-trained models. Only the model name (e.g., segmentation_spleen) is required as an input.
  • A model included in a MONAI Bundle provided via a zip archive. The model name must exactly match the name defined in the MONAI Bundle File input.


MONAI Bundle Files (See Appendix B)


 A MONAI Bundle is a self-contained directory structure that includes everything needed to train, evaluate, and deploy a medical imaging model. It typically contains configuration files, model weights, scripts, and metadata.

A collection of pre-trained models packaged as MONAI Bundles can be found in the MONAI Model Zoo which includes a collection of pre-trained imaging models that are packaged in the MONAI Bundle format.

Starting the application

To begin:

  • Click the Run button at the top of the page.
  • A new page for selecting inputs will be displayed.
    In this example, we have selected 3 files from the Bulk folder.

Usage example: Working with DICOM images Dixon Abdominal MRI images, in the DICOM format - Field 20201

In this example, we load 3 DICOM images from Field ID: 20204 and have selected the pre-trained segmentation model in the Model Input section.

  • Instance: mem2_ssd1_v2_x4 (default)
  • Priority: High (recommended)  More information on Priority Levels

When working with DICOM images, ensure the following setting is enabled:

  • Use DICOM Image File Format - Set to TRUE
    (Found under Image Input Options)

The session duration is a required input, please note:

  • Longer durations may incur higher costs if not terminated early.
  • However, they are useful for returning to work later.

After launching, the job will appear in the Monitor tab of your RAP project. To check if the session is ready:

  • Click the three dots next to the job.
  • Select View Log.
  • Wait to see the message:
    3D Slicer started
    This typically takes ~10 minutes, depending on input size and type.

The 3D Slicer interface will be displayed once the session opens.

Importing DICOM files:

Since we are working with DICOM images:

  1. Click the Welcome to Slicer tab.
  2. Go to Utilities, then Import DICOM Zip Archives
  3. Browse files (e.g., studies folder)
  4. Select all files and click Open

This will load the files into the DICOM database, similar to the standalone 3D Slicer application.

For more details, refer to the article: View Images on UKB-RAP with 3D Slicer

Files will then show in the DICOM database and the series data for each participant can be loaded. The left side pane will display a nested view of this data.

Once the data is loaded:

  • The DICOM database will display the series data for each participant and a nested view of the data will be presented in the left-hand pane.

 

Viewing and Segmenting Data using MONAI Label

To train a model for segmentation, switch to the MONAI Label interface:

  • Click the MONAI M logo in the top panel.
  • This will open the MONAI Label interface and display the training options.

After the panel opens, click on the refresh button and see that the model has loaded.

 

Navigating samples and segmenting images:

  • Click Next Sample to move to the next image. 
  • Use the Segment Editor panel to manually segment organs. In this example you can see the liver labelled in red.
  • Click Submit Label to save changes. N.B. You must submit the label before moving to the next sample. If you skip this step, your work will not be saved.
  • Click Show 3D to display the labelled structures in three dimensions.

Training the model:

  • After submitting labels for one or more samples, click Train to update the model using the newly submitted labels.
  • After training begins, the Active Learning progress panel will increase, indicating that the model is learning from inputs.
  • Click the Run button to apply the trained segmentation model to the current image.

Uploading label to your UKB-RAP project:

  • Once labelling is complete, you must upload your labels to your RAP project to preserve your work. If the session ends before uploading, your labels will be lost.

To upload

  • Open the DNAnexus File Manager.
  • Click Upload Labels and monitor progress via the Manage button.

 

Appendix A: 

Creating a Manifest File of Image or Image Archive Files

The manifest should be a plain text file with one file ID per line, formatted as:

<project ID>:<file ID>

For example:

project-AbCdE12F34G:file-HI12JK34LM56OP  
project-AbCdE12F34G:file-QR12ST34UV56WX

The following command in the terminal can be used to generate a list of file IDs for a specific field (e.g., for field ID 20252):

dx find data --property field_id=20252
 

This command will return the project ID, file ID, and file name, which typically includes the participant ID, making it easier to identify relevant imaging files.

 

Appendix B: 

Making Model Bundles ZIP files to use for the Model Bundles Input Parameter
  1. Using a JupyterLab terminal or your local command line, run: 
    python -m monai.bundle download "spleen_ct_segmentation" --bundle_dir "bundles/"
  2. Change directory into the bundles/ directory: 
    cd bundles
    ls
  3. If you only see a spleen_ct_segmentation/ directory, but not a zip file, you have to zip the directory yourself: 
    zip -r spleen_ct_segmentation.zip spleen_ct_segmentation
  4. Then upload to your UKB-RAP project:
    dx upload spleen_ct_segmentation.zip
 

Was this article helpful?

1 out of 1 found this helpful

Have more questions? Submit a request

Comments

0 comments

Please sign in to leave a comment.