Nodule Generation Algorithm
This codebase implements a simple baseline model, by following the main steps in the paper published by Litjens et al. for nodule generation track in NODE21. It contains all necessary files to build a docker image which can be submitted as an algorithm on the grand-challenge platform. Participants in the generation track can use this codebase as a template to understand how to create their own algorithm for submission.
To serve this algorithm in a docker container compatible with the requirements of grand-challenge, we used evalutils which provides methods to wrap your algorithm in Docker containers. It automatically generates template scripts for your container files, and creates commands for building, testing, and exporting the algorithm container. We adapted this template code for our algorithm by following the general tutorial on how to create a grand-challenge algorithm.
We also explain this template repository, and how to set up your docker container in this video. Before diving into the details of this template code we recommend readers have the pre-requisites installed and have cloned this repository as described below:
Prerequisites
The code in this repository is based on docker and evalutils.
Windows Tip: For participants using Windows, it is highly recommended to install Windows Subsystem for Linux (WSL) to work with Docker on a Linux environment within Windows. Please make sure to install WSL 2 by following the instructions on the same page. The alternative is to work purely out of Ubuntu, or any other flavor of Linux. Also, note that the basic version of WSL 2 does not come with GPU support. Please watch the official tutorial by Microsoft on installing WSL 2 with GPU support.
Please clone the repository as follows:
git clone git@github.com:node21challenge/node21_generation_baseline.git
Table of Contents
An overview of the baseline algorithm
Configuring the Docker File
Export your algorithm container
Submit your algorithm
An overview of the baseline algorithm
The baseline nodule generation algorithm is based on the paper published by Litjens et al.. The main file executed by the docker container is process.py.
Input and output interfaces
The algorithm needs to generate nodules on a given chest X-ray image (CXR) at requested locations (given in a .json file) and return a CXR after placing nodules. The nodule generation algorithm takes as input a chest X-ray (CXR) and a nodules.json file, which holds the coordinates location of where to generate the nodules. The algorithm reads the input :
- CXR at
"/input/
.mha" - nodules.json file at
"/input/nodules.json"
.
and writes the output to: /output/
The nodules.json file contains the predicted bounding box locations and associated nodule likelihoods (probabilities). This file is a dictionary and contains multiple 2D bounding boxes coordinates in CIRRUS compatible format. The coordinates are expected in milimiters when spacing information is available. An example nodules.json file is as follows:
{
"type": "Multiple 2D bounding boxes",
"boxes": [
{
"corners": [
[ 92.66666412353516, 136.06668090820312, 0],
[ 54.79999923706055, 136.06668090820312, 0],
[ 54.79999923706055, 95.53333282470703, 0],
[ 92.66666412353516, 95.53333282470703, 0]
]},
{
"corners": [
[ 92.66666412353516, 136.06668090820312, 0],
[ 54.79999923706055, 136.06668090820312, 0],
[ 54.79999923706055, 95.53333282470703, 0],
[ 92.66666412353516, 95.53333282470703, 0]
]}
],
"version": { "major": 1, "minor": 0 }
}
The implementation of the algorithm inference in process.py is straightforward (and must be followed by participants creating their own algorithm): load the nodules.json file in the init function of the class, and implement a function called predict to generate nodules on a given CXR image.
The function predict is run by evalutils when the process function is called.
Operating on a 3D image
For the sake of time efficiency in the evaluation process of NODE21, the submitted algorithms to NODE21 are expected to operate on a 3D image which consists of multiple CXR images stacked together. The algorithm should go through the slices (CXR images) one by one and process them individually, as shown in predict. When outputting results, the third coordinate of the bounding box in nodules.json file is used to identify the CXR from the stack. If the algorithm processes the first CXR image in 3D volume, the z coordinate output should be 0, if it processes the third CXR image, it should be 2, etc.
Configure the Docker file
Build, test and export your container
-
Switch to the correct algorithm folder at algorithms/nodulegeneration. To test if all dependencies are met, you can run the file build.bat (Windows) / build.sh (Linux) to build the docker container. Please note that the next step (testing the container) also runs a build, so this step is not necessary if you are certain that everything is set up correctly.
build.sh/build.bat files will run the following command to build the docker for you:
docker build -t nodulegenerator .
-
To test the docker container to see if it works as expected, test.sh/test.bat will run the container on images provided in
test/
folder, and it will check the results (results.json produced by your algorithm) againsttest/expected_output.json
. Please update yourtest/expected_output.json
according to your algorithm result when it is run on the test data.. ./test.sh
If the test runs successfully you will see the message Tests successfully passed... at the end of the output.
Once you validated that the algorithm works as expected, you might want to simply run the algorithm on the test folder and check the output images for yourself. If you are on a native Linux system you will need to create a results folder that the docker container can write to as follows (WSL users can skip this step) (Note that $SCRIPTPATH was created in the previous test script).
mkdir $SCRIPTPATH/results chmod 777 $SCRIPTPATH/results
To write the output of the algorithm to the results folder use the following command (note that $SCRIPTPATH was created in the previous test script):
docker run --rm --memory=11g -v $SCRIPTPATH/test:/input/ -v $SCRIPTPATH/results:/output/ nodulegenerator
-
Run export.sh/export.bat to save the docker image which runs the following command:
docker save nodulegenerator | gzip -c > nodulegenerator.tar.gz
Submit your algorithm
Details of how to create an algorithm on grand-challenge and submit it to the node21 challenge will be added here soon.
Please make sure all steps described above work as expected before proceeding. Ensure also that you have an account on grand-challenge.org and that you are a verified user there.