ivadomed: A Medical Imaging Deep Learning Toolbox

ivadomed is an open-source Python package for designing, end-to-end training, and evaluating deep learning models applied to medical imaging data. The package includes APIs, command-line tools, documentation, and tutorials. ivadomed also includes pre-trained models such as spinal tumor segmentation and vertebral labeling. Original features of ivadomed include a data loader that can parse image metadata (e.g., acquisition parameters, image contrast, resolution) and subject metadata (e.g., pathology, age, sex) for custom data splitting or extra information during training and evaluation. Any dataset following the Brain Imaging Data Structure (BIDS) convention will be compatible with ivadomed without the need to manually organize the data, which is typically a tedious task. Beyond the traditional deep learning methods, ivadomed features cutting-edge architectures, such as FiLM and HeMis, as well as various uncertainty estimation methods (aleatoric and epistemic), and losses adapted to imbalanced classes and non-binary predictions. Each step is conveniently configurable via a single file. At the same time, the code is highly modular to allow addition/modification of an architecture or pre/post-processing steps. Example applications of ivadomed include MRI object detection, segmentation, and labeling of anatomical and pathological structures. Overall, ivadomed enables easy and quick exploration of the latest advances in deep learning for medical imaging applications. ivadomed's main project page is available at https://ivadomed.org.


Introduction
Deep learning is increasingly used in medical image processing (Kim et al., 2019). It provides automated solutions to repetitive and/or tedious tasks such as the segmentation of pathological structures. However, medical imaging data present many challenges: datasets are often not publicly-available, ground truth labels are scarce due to the limited availability of expert raters, and needs can be very specific and tailored to particular datasets (e.g., segmentation of spinal tumors on sagittal MRI T2-weighted scans). Thus, offering solution for convenient training models (or fine-tuning of pre-existing models) is needed.
We present ivadomed, a deep learning toolbox dedicated to medical data processing. ivadomed aims to support the integration of deep learning models into the clinical routine, as well as state-of-the-art academic biomedical research. It features intuitive command-line tools for end-to-end training and evaluation of various deep learning models. The package also includes pre-trained models that can be used to accommodate specific datasets with transfer learning.
Another challenge of medical imaging is the heterogeneity of the data across clinical centers, in terms of image features (e.g., contrast, resolution) and population demographics. This makes it challenging to create models that can generalize well across the many existing datasets. Recent cutting-edge methods address this problem, such as FiLM (Perez et al., 2017) and HeMis (Havaei et al., 2016), however they are usually not implemented within a comprehensive framework that enables end-to-end training and experimentation. In addition to providing these advanced architectures, ivadomed features multiple uncertainty estimation methods (aleatoric and epistemic), losses adapted to imbalanced classes and non-binary predictions. Each step can be conveniently customized via a single configuration file, and at the same time, the code is highly modular to allow addition/modification of architecture or pre-/post-processing steps.
ivadomed is based on PyTorch framework (Paszke et al., 2017) with GPU acceleration supported by CUDA. It can easily be installed via PyPI and the whole package is tested with a continuous integration framework. The project website, which includes user and API documentation, is available at https://ivadomed.org. The name ivadomed is a portmanteau between IVADO (The Institute for data valorization) and medical.

Software Description
Loader: An important aspect of machine learning is data management. Lots of time is usually spent manually organizing data into a proper structure to make the dataset compatible with a chosen analysis pipeline (Willemink et al., 2020). ivadomed features a data loader module that expects datasets to be structured according to a widely-accepted convention: the Brain Imaging Data Structure (BIDS) (Gorgolewski et al., 2016). Thus, any dataset following the BIDS convention can immediately be used by ivadomed, e.g., for training a new model, without the need to spend time organizing the data. BIDS convention is designed around neuroimaging MRI data and accepts NIfTI file formats, but the BIDS community is actively expanding its specifications to other modalities (CT, MEG/EEG, microscopy) and file formats (PNG, OME-TIFF), which ivadomed will then be able to accommodate.
One benefit of the BIDS convention is that each image file is associated with a JSON file containing metadata. ivadomed's loader can parse image metadata (e.g., acquisition parameters, image contrast, resolution) and subject metadata (e.g., pathology, age, sex) for custom data splitting or extra information during training and evaluation. It is possible to modulate specific layers of a convolutional neural network using metadata information (e.g., image contrast, data center, disease phenotype), to tailor it towards a particular data domain or to enable experiments with architectures such as FiLM (Perez et al., 2017) (which is implemented in ivadomed). Metadata could also be useful to mitigate class imbalance via data balancing techniques.
ivadomed's data loader can accommodate 2D/3D images, multiple input channels as well as multiple prediction classes. Images can be loaded as a volume, slice-wise, or patchwise. Data can be saved on the RAM or used "on the fly" via HDF5 format. Cropping, resampling, normalization, and histogram clipping and equalization can be applied during the loading as a pre-processing step. ivadomed can deal with missing modalities (Havaei et al., 2016) by resorting to curriculum learning to train the model.
Training: ivadomed includes all the necessary components for training segmentation models from start to finish. The first step usually consists of applying data augmentation transformations, such as affine, elastic, and ground-truth dilation, which are all included in ivadomed. The next step is model training, which can be done either from scratch or using transfer learning on a pre-trained model by freezing some layers. Available architectures include: 2D U-Net (Ronneberger et al., 2015), 3D U-Net (Isensee et al., 2017), ResNet (He et al., 2016), DenseNet (Huang et al., 2017), Count-ception (Cohen et al., 2017), and HeMIS U-Net. These models can easily be enriched via attention blocks (Oktay et al., 2018) or FiLM layers (which modulate U-Net features using metadata). To facilitate the training process, ivadomed offers multiple loss functions such as the Dice coefficient (Milletari et al., 2016), cross-entropy, and L2 norm, including some adapted to medical imaging challenges, such as the adaptive wing loss (Wang et al., 2019b) for soft labels and the focal Dice loss (Wong et al., 2018) for class imbalance. To partly address the problem of small datasets, mixup (Zhang et al., 2017) has been implemented and adapted for segmentation tasks. To mitigate class imbalance, ivadomed supports cascaded architectures. With a single inference, it is possible to narrow down the region of interest via object detection, and then segment a specific structure. In case of interruption during training, all parameters are saved after each epoch so that training can be resumed at any time.
It can be overwhelming to get started and choose across all the available models, losses, and parameters. ivadomed's repository includes the script ivadomed automate training to configure and launch multiple trainings across GPUs. In addition, ivadomed includes tutorials that cover typical training scenarios such as one-class segmentation, cascade of architectures, and uncertainty estimation. Evaluation: A model can be thoroughly evaluated on the testing set by computing various popular metrics for segmentation, classification, and regression tasks. Slice-wise or patch-wise predictions are reconstructed in the initial space for evaluation and output visualization. ivadomed can produce aleatoric (Wang et al., 2019a) and/or epistemic (Nair et al., 2018) uncertainty, voxel-wise and/or object-wise (Roy et al., 2018, using multiple available measures (e.g., entropy, coefficient of variation). Results are reported in a CSV file. The evaluation framework can be further customized with post-processing (e.g., fill holes, remove small objects, thresholding using uncertainty). It is also possible to compute metrics for specific object sizes (e.g., small vs. large lesions). ivadomed has a module to find the optimal threshold value on the output soft prediction, via a grid-search finding applied to evaluation metrics or ROC curve.
Multiple visualization tools are included in ivadomed to support the design and optimization of tailored training models: GIF animations across training epochs, visual quality control of data augmentation, training curve plots, integration of the TensorBoard module, and output images with true/false positive labels.

Usage
Use case 1 -Spinal Cord Toolbox: Spinal cord toolbox (SCT) is an open-source analysis software package for processing MRI data of the spinal cord (De Leener et al., 2017). ivadomed is SCT's backbone for the automated segmentation of the spinal cord, gray matter, tumors, and multiple sclerosis lesions, as well as for the labeling of intervertebral discs.
Use case 2 -Creation of anatomical template: ivadomed was used in the generation of several high-resolution anatomical MRI templates (Calabrese et al., 2018;. To make anatomical templates, it is sometimes necessary to segment anatomical regions, such as the spinal cord white matter. When dealing with high resolution data, there may be several thousand 2D slices to segment, stressing the need for a fully-automated and robust solution. In these studies, only a handful of slices were manually-segmented and used to train a specific model. The model then predicted reliably and with high accuracy (Dice score >90%) the delineation of anatomical structures for the thousands of remaining unlabeled slices.
Use case 3 -Tumor segmentation: ivadomed also proves to be useful in the context of clinical radiology routine (Lemay et al., 2020), where clinicians need to segment tumors, edema, and cavity to establish prognosis and monitor the outcome. The framework is composed of a cascaded architecture that detects the spinal cord, crops the image around the region of interest, and segments the tumor (Figure 2). The resulting model can be applied to new data using only CPUs, which is more convenient in the clinical setting. The advanced features and architectures available in ivadomed, such as FiLM, were pivotal in obtaining encouraging results despite the difficulty of the task and the relatively low number of images. Step 1: The spinal cord is localized using a 3D U-Net and the image is cropped around the generated mask.
Step 2: The spinal cord tumors are segmented.