Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
49a5920
Add BraTS integration with MLCube
davidjurado Jan 11, 2022
40d335c
Fix README
davidjurado Jan 11, 2022
1e014cb
Refactor folder project to make it more understandable
davidjurado Feb 11, 2022
3a1d28c
Add project workflow diagram
davidjurado Feb 11, 2022
3a8bae6
Fix typos
davidjurado Feb 11, 2022
b9d2b2d
Add missing command
davidjurado Feb 11, 2022
6c9536c
Refactor project to match MedPerf specifications
davidjurado Feb 16, 2022
597fc44
Refactor project and add metrics MLCube
davidjurado Feb 18, 2022
bbbf85a
Add comments to metrics file
davidjurado Feb 18, 2022
02fe758
Fix readme
davidjurado Feb 18, 2022
6cfe2dc
Add preprocess MLCube
davidjurado Feb 25, 2022
8521cf0
Update preprocessing MLCube task
davidjurado Mar 16, 2022
37730f4
Update readme
davidjurado Mar 18, 2022
aa4dfda
Fix preprocessing mlcube.yaml file
davidjurado Mar 18, 2022
8376c35
Fix preprocessing sanity check
davidjurado Mar 18, 2022
5de23b9
Add missing task for preprocessing MLCube
davidjurado Mar 18, 2022
bce60ed
Add model MLCube
davidjurado Mar 18, 2022
f47949b
Fix metrics MLCube
davidjurado Mar 18, 2022
7d13bc5
Fix model MLCube
davidjurado Mar 18, 2022
9ecfc19
Fix model paths
davidjurado Mar 18, 2022
0434321
Fix preprocessing logic
davidjurado Mar 22, 2022
10bbfe6
Fix model logic
davidjurado Mar 25, 2022
cc0fc40
Fix model files
davidjurado Mar 25, 2022
ab20d9b
Add dataset in tar format
davidjurado Mar 25, 2022
128c691
Add preprocessing output as model input
davidjurado Mar 25, 2022
7fc2387
Update Readme
davidjurado Apr 8, 2022
4b840fe
Fix Docker image convertion to Singularity
davidjurado Apr 28, 2022
81f7aff
Merge branch 'feature/brats' of github.com:davidjurado/mlcube_example…
davidjurado Apr 28, 2022
45a44d9
Add Docker to singularity instructions
davidjurado Apr 29, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions brats/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# author info
AUTHOR_NAME = "Chuck Norris"
AUTHOR_EMAIL = "[email protected]"
# put your app name here
APPLICATION_NAME = "AMAZING APPLICATION"
# specify version here, if possible use semantic versioning
APPLICATION_VERSION = "0.0.1"

INPUT_FOLDER ="workspace/data/"
OUTPUT_FOLDER ="workspace/data/results/"

INPUT_FOLDER_DOCKER="/app/data/"
OUTPUT_FOLDER_DOCKER ="/app/data/results/"
1 change: 1 addition & 0 deletions brats/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__pycache__/
22 changes: 22 additions & 0 deletions brats/Dockerfile_CPU
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# for a CPU app use this Dockerfile, delete the Dockerfile_CUDA then.
FROM python:3.8-buster

# fill in your info here
LABEL author="[email protected]"
LABEL application="your application name"
LABEL maintainer="[email protected]"
LABEL version="0.0.1"
LABEL status="beta"

# basic
RUN apt-get -y update && apt -y full-upgrade && apt-get -y install apt-utils wget git tar build-essential curl nano

# install all python requirements
WORKDIR /app
COPY ./requirements.txt ./requirements.txt
RUN pip3 install -r requirements.txt

# copy all files
COPY ./ ./

ENTRYPOINT [ "python3","-u", "run.py"]
27 changes: 27 additions & 0 deletions brats/Dockerfile_CUDA
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# for a GPU app use this Dockerfile, delete the Dockerfile_CPU then.
FROM nvidia/cuda:10.1-cudnn7-runtime-ubuntu18.04

# fill in your info here
LABEL author="[email protected]"
LABEL application="your application name"
LABEL maintainer="[email protected]"
# specify version here, if possible use semantic versioning
LABEL version="0.0.1"
LABEL status="beta"

# basic
RUN apt-get -y update && apt -y full-upgrade && apt-get -y install apt-utils wget git tar build-essential curl nano

# install python 3.6.9
RUN apt-get update -y && apt-get install -y python3-pip python3-dev

# install all python requirements
WORKDIR /app
COPY ./requirements.txt ./requirements.txt
RUN pip3 install -r requirements.txt

# copy all files
COPY ./ ./
RUN pip3 install -U python-dotenv

ENTRYPOINT [ "python3","-u", "run.py"]
661 changes: 661 additions & 0 deletions brats/LICENSE

Large diffs are not rendered by default.

35 changes: 35 additions & 0 deletions brats/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# BraTS Challenge 2020 - MLCube integration

Original implementation: ["BraTS Instructions Repo"](https://github.com/BraTS/Instructions)

## Dataset

Please refer to the [BraTS challenge page](http://braintumorsegmentation.org/) and follow the instructions in the data section.

## Project setup

```bash
# Create Python environment and install MLCube Docker runner
virtualenv -p python3 ./env && source ./env/bin/activate && pip install mlcube-docker

# Fetch the boston housing example from GitHub
git clone https://github.com/mlcommons/mlcube_examples && cd ./mlcube_examples
git fetch origin pull/39/head:feature/brats && git checkout feature/brats
cd ./brats
```

## Tasks execution

```bash
# Run implementation with CPU support.
mlcube run --mlcube=mlcube_cpu.yaml --task=run

# Run implementation with GPU support.
mlcube run --mlcube=mlcube_gpu.yaml --task=run
```

We are targeting pull-type installation, so MLCube images should be available on Docker Hub. If not, try this:

```Bash
mlcube run ... -Pdocker.build_strategy=always
```
22 changes: 22 additions & 0 deletions brats/mlcube_cpu.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: MLCommons Brats
description: MLCommons Brats integration
authors:
- {name: "MLCommons Best Practices Working Group"}

platform:
accelerator_count: 0

docker:
# Image name.
image: mlcommons/brats_cpu:0.0.1
# Docker build context relative to $MLCUBE_ROOT. Default is `build`.
build_context: "."
# Docker file name within docker build context, default is `Dockerfile`.
build_file: "Dockerfile_CPU"

tasks:
run:
# Run implementation
parameters:
inputs: {data_dir: data/}
outputs: {results_dir: data/results/}
22 changes: 22 additions & 0 deletions brats/mlcube_gpu.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: MLCommons Brats
description: MLCommons Brats integration
authors:
- {name: "MLCommons Best Practices Working Group"}

platform:
accelerator_count: 0

docker:
# Image name.
image: mlcommons/brats_gpu:0.0.1
# Docker build context relative to $MLCUBE_ROOT. Default is `build`.
build_context: "."
# Docker file name within docker build context, default is `Dockerfile`.
build_file: "Dockerfile_CUDA"

tasks:
run:
# Run implementation
parameters:
inputs: {data_dir: data/}
outputs: {results_dir: data/results/}
1 change: 1 addition & 0 deletions brats/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
python-dotenv==0.12.0
21 changes: 21 additions & 0 deletions brats/run.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"""Load code"""
import argparse
from src.amazing_logic import run_code

parser = argparse.ArgumentParser()
parser.add_argument(
"--data_dir",
type=str,
default=None,
help="Path to dataset.",
)
parser.add_argument(
"--results_dir",
type=str,
default=None,
help="Path to output folder.",
)
args, _unkown = parser.parse_known_args()

# execute
run_code(args)
Empty file added brats/src/__init__.py
Empty file.
38 changes: 38 additions & 0 deletions brats/src/amazing_logic.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
"""Logic file"""
import os
from shutil import copyfile
from dotenv import dotenv_values
from src.utils.utilities import helper

config = dotenv_values(".env")
APPLICATION_NAME = config["APPLICATION_NAME"]
APPLICATION_VERSION = config["APPLICATION_VERSION"]
INPUT_FOLDER = config["INPUT_FOLDER"]
Copy link

Choose a reason for hiding this comment

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

Read INPUT_FOLDER and OUTPUT_FOLDER from --data_dir and --results_dir only; and taken them out of the .env file

OUTPUT_FOLDER = config["OUTPUT_FOLDER"]


def logic_wrapper(args):
"""Edit your logic here"""
if args.data_dir is not None:
INPUT_FOLDER = args.data_dir
input_file = os.path.normpath(INPUT_FOLDER + "/something_t1.nii.gz")
# ... do the same for t1c, flair and t2 here
if args.results_dir is not None:
OUTPUT_FOLDER = args.results_dir
output_file = os.path.normpath(OUTPUT_FOLDER + "/something_seg.nii.gz")

# copy paste your amazing logic here
print("wrapper: I can feel the magic happening..it feels like a little sun rising inside me!")

# example logic
copyfile(input_file, output_file)
helper()


def run_code(args):
"""Main function"""
print("*** code execution started:",
APPLICATION_NAME, "version:", APPLICATION_VERSION, "! ***")
logic_wrapper(args)
print("*** code execution finished:",
APPLICATION_NAME, "version:", APPLICATION_VERSION, "! ***")
Empty file added brats/src/utils/__init__.py
Empty file.
4 changes: 4 additions & 0 deletions brats/src/utils/utilities.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"""utility functions here"""
def helper():
"""helper function"""
print("helper: I am so useful it hurts.")
1 change: 1 addition & 0 deletions brats/workspace/data/results/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
output.nii.gz
3 changes: 3 additions & 0 deletions brats/workspace/data/results/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*
!.gitignore
!.dockerignore
1 change: 1 addition & 0 deletions brats/workspace/data/something_flair.nii.gz
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
I am a standardized compressed nifti file!
14 changes: 14 additions & 0 deletions brats/workspace/data/something_survival_metadata.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
exam_id,age,resection_status
something,NA,NA

First column: exam name, string for the exam name
Second Column: Age as a float or NA for missing
Third Column: resection status as NA for missing, GTR/STR as a string

ATTENTION: note the slightly changed column names in comparison to what you received for testing

Example for a case without missing data:

exam_id,age,resection_status
BraTS20_Testing_015,51.449,GTR

1 change: 1 addition & 0 deletions brats/workspace/data/something_t1.nii.gz
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
I am a standardized compressed nifti file!
1 change: 1 addition & 0 deletions brats/workspace/data/something_t1ce.nii.gz
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
I am a standardized compressed nifti file!
1 change: 1 addition & 0 deletions brats/workspace/data/someting_t2.nii.gz
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
I am a standardized compressed nifti file!