IVDM3Seg
  • Overview
  • Tasks
  • Data
  • METHODS
    • SUBMIT
    • DOCKERFILE
    • EXAMPLE: PYTHON
  • RESULTS
    • MICCAI2018
    • __________________
    • lrde
    • ucsf_Claudia
    • wanghuan
    • gaoyunhe_cuhk
    • livia
    • mader
    • changliu
    • smartsoft
    • smartsoftV2
  • Dates
  • Metrics
  • Organizers

Example: python


This page shows a simple example on how to containerize your python script for this challenge. The source code can also be found at github for our challenge: zengguodong/IVDM3SegChallenge.

The following python script simply thresholds the  image at gray value 20. At the moment, it uses the SimpleITK BinaryThreshold function.
​
​import os
import SimpleITK as sitk
​
inputDir = '/input'
outputDir = '/output'

# Load the image
fatImage = sitk.ReadImage(os.path.join(inputDir, 'fat.nii.gz'))
innImage = sitk.ReadImage(os.path.join(inputDir, 'inn.nii.gz'))
oppImage = sitk.ReadImage(os.path.join(inputDir, 'opp.nii.gz'))
watImage = sitk.ReadImage(os.path.join(inputDir, 'wat.nii.gz'))

# SimpleITK: binary threshold between 0 - 20
resultImage = sitk.BinaryThreshold(fatImage, lowerThreshold=0, upperThreshold=20)

sitk.WriteImage(resultImage, os.path.join(outputDir, 'segmentation_result.nii.gz'))

​
This code needs a basic Python installation, with numpy and SimpleITK added. We therefore used miniconda, which has Docker container available that we can inherit from: continuumio/miniconda.
​
Our Dockerfile looks like this:
​
FROM continuumio/miniconda
MAINTAINER IPMI_Bern
RUN pip install numpy SimpleITK
ADD python/src /ivdm3seg

Our Python code is saved next to this Dockerfile in the folder python/src/Segmentation.py.  With the following command, we build a Docker container from our Dockerfile and the Python source code:
​
​docker build -f Dockerfile -t ivdm3seg/[TEAM-NAME] . 

​Note: the "." at the end specifies that everything is in the current folder. Hence, you run this build command from the folder that contains the Dockerfile and the source code.  [TEAM-NAME] should be replaced by your unique team name. ​
​
Because the segmentation code is run in the docker, we need to map the input folder which contains IVD data on our machine into the docker.   we can run it with the following command:
​
​docker run -dit -v [TEST-DIR]:/input:ro -v /output ivdm3seg/[TEAM-NAME]
​
​The first -v options map the input folder into the Docker container at /input.  The second -v creates an output directory. [TEST-DIR] should be replaced by the absolute folder path which contains 4 test volumes: "fat.nii.gz", "inn.nii.gz", "opp.nii.gz" and "wat.nii.gz". [TEAM-NAME] should be replaced by your unique team name.

​Run the segmentation script in Docker


​Use the command “docker ps” to find the "Container ID" and then run the segmentation script: 
​
docker exec [CONTAINER-ID] python /ivdm3seg/Segmentation.py
​
​Now we need to copy the segmentation result from the Docker container to your local machine:

docker cp [CONTAINER-ID]:/output [RESULT-LOCATION] 

​ [CONTAINER-ID] should be replaced by the container id retrieved by running  the command “docker ps”. 
[RESULT-LOCATION]  should be replaced by the path on your local machine where you intend to save the segmentation results. 

​

Save Your Docker

Use the command below to save your docker:

​docker save ivdm3seg/[TEAM-NAME] > [TEAM-NAME].tar 
​

 All participants should send the organizer this saved  file, i.e. [TEAM-NAME].tar, and then the organizer can run this Docker on our machine to do the test. 
​

Test your Docker

Use the command below to load your docker:

docker load --input [TEAM-NAME].tar

Then you can run the segmentation code from loaded Docker to test whether it works well.

Finally, we shut down the running container. This also removes the created /output folder and any other changes made to the container.
​

docker rm -v [CONTAINER-ID]
Powered by Create your own unique website with customizable templates.
  • Overview
  • Tasks
  • Data
  • METHODS
    • SUBMIT
    • DOCKERFILE
    • EXAMPLE: PYTHON
  • RESULTS
    • MICCAI2018
    • __________________
    • lrde
    • ucsf_Claudia
    • wanghuan
    • gaoyunhe_cuhk
    • livia
    • mader
    • changliu
    • smartsoft
    • smartsoftV2
  • Dates
  • Metrics
  • Organizers