Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates aide-svrtk MAP with MONAI-based CNN #13

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<p align="center">
<h1 align="center">aide-svrtk</h1>
<p align="center">
AI-driven, automated <a href="https://github.com/SVRTK/SVRTK">SVR reconstruction</a> packaged as an AIDE Application, based on
AI-driven, <a href="https://github.com/SVRTK/auto-proc-svrtk">automated</a> version of <a href="https://github.com/SVRTK/SVRTK">SVR reconstruction</a> packaged as an AIDE Application, based on
the open-source <a href="https://github.com/Project-MONAI/monai-deploy/blob/main/guidelines/monai-application-package.md">
MONAI Application Package (MAP)</a> standard.
<br />
Expand All @@ -20,14 +20,14 @@

The slice-to-volume reconstruction toolkit ([SVRTK](https://github.com/SVRTK/SVRTK)) is an image-based registration
framework for reconstruction of 3D volumes from multiple 2D image slices. SVRTK is used extensively for performing
motion-corrected reconstruction of MRI data.
motion-corrected reconstruction of MRI data. The [automated SVR](https://github.com/SVRTK/auto-proc-svrtk) version employs deep learning [MONAI](https://github.com/Project-MONAI/MONAI) networks for localisation and reorientation of the brain to the standard radiological space.

Currently, this MAP implements SVRTK for reconstruction of 2D **fetal brain MRI** data into motion-corrected 3D volumes.
Further MAPs for reconstruction of other fetal organs are in development and coming soon.

[AIDE](https://www.aicentre.co.uk/platforms#view1) is an open-source platform for the deployment of AI applications in
healthcare settings. This repo, created and led by [Tom Roberts](https://github.com/tomaroberts), packages automated
3D fetal brain MRI reconstruction into a [MONAI Application Package (MAP)](https://github.com/Project-MONAI/monai-deploy)
healthcare settings. This repo, created and led by [Tom Roberts](https://github.com/tomaroberts), packages [automated
3D fetal brain MRI reconstruction](https://github.com/SVRTK/auto-proc-svrtk) into a [MONAI Application Package (MAP)](https://github.com/Project-MONAI/monai-deploy)
for execution on AIDE, and other platforms compatible with the MAP standard.

## aide-svrtk MAP workflow
Expand All @@ -38,7 +38,7 @@ MRI DICOM Series contained the motion-corrected reconstruction.
The aide-svrtk MAP consists of three operators:
1. `dcm2nii_operator.py` – converts the input 2D MRI DICOM Series into NIfTI format required by SVRTK, using
[dcm2niix](https://github.com/rordenlab/dcm2niix)
2. `fetal_mri_3d_brain_recon_operator.py` – runs automated fetal brain SVRTK reconstruction, in three main steps:
2. `fetal_mri_3d_brain_recon_operator.py` – runs [automated fetal brain SVRTK reconstruction](https://github.com/SVRTK/auto-proc-svrtk), in three main steps:
a. AI-driven brain masking
b. Slice-to-volume registration reconstruction
c. AI-driven brain reorientation
Expand Down Expand Up @@ -98,31 +98,31 @@ The final MAP is called `map`

```shell
# Initial packaging of MAP
monai-deploy package app -t ghcr.io/svrtk/aide-svrtk/map-init:0.2.0 -r requirements.txt -l DEBUG
monai-deploy package app -t ghcr.io/svrtk/aide-svrtk/map-init:0.2.1 -r requirements.txt -l DEBUG

# Build 3rd-party software on top of MAP
docker build -t ghcr.io/svrtk/aide-svrtk/map:0.2.0 app/
docker build -t ghcr.io/svrtk/aide-svrtk/map:0.2.1 app/

# Test MAP with MONAI Deploy
monai-deploy run ghcr.io/svrtk/aide-svrtk/map:0.2.0 input/ output/
monai-deploy run ghcr.io/svrtk/aide-svrtk/map:0.2.1 input/ output/

# Push initial MAP and final MAP to GHCR
docker push ghcr.io/svrtk/aide-svrtk/map-init:0.2.0
docker push ghcr.io/svrtk/aide-svrtk/map:0.2.0
docker push ghcr.io/svrtk/aide-svrtk/map-init:0.2.1
docker push ghcr.io/svrtk/aide-svrtk/map:0.2.1
```

## Optional

Enter Docker container for testing

```shell
docker run --gpus all -it --rm -v local/path/to/aide-svrtk/input:/var/monai/input/ --entrypoint /bin/bash ghcr.io/svrtk/aide-svrtk/map:0.2.0
docker run --gpus all -it --rm -v local/path/to/aide-svrtk/input:/var/monai/input/ --entrypoint /bin/bash ghcr.io/svrtk/aide-svrtk/map:0.2.1
```

Run on specified GPU if machine has >1 available

```shell
CUDA_VISIBLE_DEVICES=2 monai-deploy run ghcr.io/svrtk/aide-svrtk/map:0.2.0 input/ output/
CUDA_VISIBLE_DEVICES=2 monai-deploy run ghcr.io/svrtk/aide-svrtk/map:0.2.1 input/ output/
```

## Running on AIDE
Expand Down
40 changes: 22 additions & 18 deletions app/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM ghcr.io/svrtk/aide-svrtk/map-init:0.2.0 AS build
FROM ghcr.io/svrtk/aide-svrtk/map-init:0.2.1 AS build

# Add dcm2niix to MAP
WORKDIR /bin
Expand All @@ -19,7 +19,7 @@ WORKDIR /var/monai

# Add SVRTK to MAP

WORKDIR /home
WORKDIR /bin

# Install general libraries
RUN apt-get update && apt-get install --no-install-recommends --no-install-suggests -y \
Expand All @@ -37,42 +37,46 @@ RUN apt-get install -y \

# Install MIRTK/SVRTK
RUN git clone https://github.com/SVRTK/MIRTK.git \
&& mkdir -p /home/MIRTK/Packages/SVRTK
RUN git clone https://github.com/SVRTK/SVRTK.git /home/MIRTK/Packages/SVRTK \
&& mkdir -p /home/MIRTK/build \
&& cd /home/MIRTK/build \
&& mkdir -p /bin/MIRTK/Packages/SVRTK
RUN git clone https://github.com/SVRTK/SVRTK.git /bin/MIRTK/Packages/SVRTK \
&& mkdir -p /bin/MIRTK/build \
&& cd /bin/MIRTK/build \
&& cmake -D WITH_TBB="ON" -D MODULE_SVRTK="ON" .. \
&& make -j

ENV PATH="$PATH:/home/MIRTK/build/bin:/home/MIRTK/build/lib/tools"
ENV PATH="$PATH:/bin/MIRTK/build/bin:/bin/MIRTK/build/lib/tools"

WORKDIR /var/monai


# Add 3D UNet model weights & execution script
# Add MONAI 3D UNet model weights & execution script

WORKDIR /home

# Setup 3D UNet models
RUN git clone https://github.com/SVRTK/Segmentation_FetalMRI.git --branch svrtk-docker-gpu-0.10 --single-branch /home/Segmentation_FetalMRI
RUN git clone https://github.com/SVRTK/auto-proc-svrtk.git /home/auto-proc-svrtk
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most of the errors are to do with this line currently. You've changed the location of the recon Shell script, but not updated the rest of the Dockerfile and Python code to reflect the new script location, so... see other comments where I can see you need to make changes.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i fixed paths and was able to run monai-deploy run ghcr.io/svrtk/aide-svrtk/map:0.2.1 input/ output/


RUN wget https://gin.g-node.org/SVRTK/fetal_mri_network_weights/raw/master/checkpoints-brain-loc-2-labels/latest.ckpt -P /home/Segmentation_FetalMRI/trained-models/checkpoints-brain-loc-labels \
&& wget https://gin.g-node.org/SVRTK/fetal_mri_network_weights/raw/master/checkpoints-brain-loc-2-labels-cropped/latest.ckpt -P /home/Segmentation_FetalMRI/trained-models/checkpoints-brain-loc-labels-cropped \
&& wget https://gin.g-node.org/SVRTK/fetal_mri_network_weights/raw/master/checkpoints-brain-reo-5-labels/latest.ckpt -P /home/Segmentation_FetalMRI/trained-models/checkpoints-brain-reorientation \
&& wget https://gin.g-node.org/SVRTK/fetal_mri_network_weights/raw/master/checkpoints-brain-reo-5-labels-raw-stacks/latest.ckpt -P /home/Segmentation_FetalMRI/trained-models/checkpoints-brain-reorientation-stacks
RUN wget https://gin.g-node.org/SVRTK/fetal_mri_network_weights/raw/master/monai-checkpoints-atunet-brain_bet_all_degree_raw_stacks-1-lab/best_metric_model.pth -P /home/auto-proc-svrtk/trained_models/monai-checkpoints-atunet-brain_bet_all_degree_raw_stacks-1-lab \
&& wget https://gin.g-node.org/SVRTK/fetal_mri_network_weights/raw/master/monai-checkpoints-unet-global-loc-2-lab/best_metric_model.pth -P /home/auto-proc-svrtk/trained_models/monai-checkpoints-unet-global-loc-2-lab \
&& wget https://gin.g-node.org/SVRTK/fetal_mri_network_weights/raw/master/monai-checkpoints-unet-svr-brain-reo-5-lab/best_metric_model.pth -P /home/auto-proc-svrtk/trained_models/monai-checkpoints-unet-svr-brain-reo-5-lab \
&& wget https://gin.g-node.org/SVRTK/fetal_mri_network_weights/raw/master/monai-checkpoints-unet-svr-brain-reo-raw-stacks-5-lab/best_metric_model.pth -P /home/auto-proc-svrtk/trained_models/monai-checkpoints-unet-svr-brain-reo-raw-stacks-5-lab

# Install Python packages
RUN python -m pip install -r /home/Segmentation_FetalMRI/requirements.txt
RUN python -m pip install -r /home/auto-proc-svrtk/config/requirements.txt

# Bugfix: without below, cannot import torch within Python
# Error: OSError: /opt/hpcx/ompi/lib/libmpi.so.40: undefined symbol: opal_hwloc201_hwloc_get_type_depth
# Fix: https://forums.developer.nvidia.com/t/issues-building-docker-image-from-ngc-container-nvcr-io-nvidia-pytorch-22-py3/209034/5
ENV PATH="${PATH}:/opt/hpcx/ompi/bin"
ENV LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:/opt/hpcx/ompi/lib"

COPY docker-recon-brain-auto.bash /home/scripts/docker-recon-brain-auto.bash
RUN mkdir -p /home/recon \
&& mkdir -p /home/output \
&& chmod +x /home/scripts/*
#COPY /home/auto-proc-svrtk/scripts/auto-brain-reconstruction-aide.sh /home/scripts/auto-brain-reconstruction.sh


RUN mkdir -p /home/recon
RUN mkdir -p /home/output
RUN mkdir -p /home/scripts
RUN chmod +x /home/auto-proc-svrtk/scripts/*


WORKDIR /var/monai
Loading