Skip to content

Commit fdd0699

Browse files
committed
Update readme and export
1 parent 9ed2d44 commit fdd0699

File tree

2 files changed

+132
-45
lines changed

2 files changed

+132
-45
lines changed

README.md

+124-44
Original file line numberDiff line numberDiff line change
@@ -56,25 +56,21 @@
5656

5757
<!-- ABOUT THE PROJECT -->
5858
## Goal
59+
The goal of this repository is to provide a seamless and efficient integration of your algorithm into the Grand Challenge platform. This repository offers a template for packaging your algorithm in a Docker container, ensuring compatibility with the input and output formats of the SynthRAD2023 challenge.
5960

60-
The source code for the participant algorithm container for
61-
SynthRAD2023, generated with
62-
evalutils version 0.3.1.
61+
With this template, you can submit your algorithm (with minimal effort) to the test phases of the challenge (and optionally the validation phases). You can use the preliminary test phase to make sure everything is in order with your submission and get an initial estimate of your algorithms performance.
6362

6463
<!-- GETTING STARTED -->
6564
## Getting Started
6665

6766
### Dependencies
6867

69-
The user should have access to Docker [https://docs.docker.com/].
70-
The requirements, specified in `requirements.txt` are:
71-
* evalutils v0.3.1
72-
* scikit-learn v0.24.2
73-
* scipy v1.6.3
74-
* scikit-image v0.19.3
75-
* SimpleITK
68+
For building the algorithm for submission, the user should have access to Docker [https://docs.docker.com/] on their system. (Note: Submissions to the test phase are allowed only with docker containers)
7669

77-
### Installation
70+
Please make sure to list the requirements for your algorithm in the `requirements.txt` file as this will be picked up when building the docker container.
71+
72+
73+
### Download
7874

7975
1. Clone the repo
8076
```sh
@@ -88,47 +84,131 @@ git clone git@github.com:SynthRAD2023/algorithm-template.git
8884

8985
### Setup
9086

91-
1. Generate dummy data with
92-
```python
93-
python create_dummy_data.py
94-
````
87+
Dummy data (randomly created scans) for testing the docker has already been provided in the `test` folder. It should be in the following format,
9588

96-
This will simulate the SynthRAD data structure with separate folders for `images` and `masks`,
97-
each file has a naming convention of
89+
```
90+
algorithm-template
91+
└── test
92+
├── images
93+
│ ├── body
94+
│ │ └── 1BAxxx.nii.gz
95+
│ └── mri
96+
│ └── 1BAxxx.nii.gz
97+
└── expected_output.json
98+
```
9899

99-
`<Task><Region><Hospital><Id_number>.<Extension>`
100+
`test/images` simulates the input data provided to the docker image while it is run on the test data by the Grand Challenge platform. `test/expected_output.json` is present to check if your algorithm provides the expected output on the inputs provided to it.
100101

101-
`Task`: 1 (mr to ct) or 2 (cbct to ct)
102102

103-
`Region`: B (brain) or P (pelvis)
103+
<!-- USAGE EXAMPLES -->
104104

105-
`Hospital`: A, B, C (Not all in every task/region)
105+
## Usage
106106

107-
`Id_number`: 3 digits
107+
First, run `test.sh`
108108

109-
`Extension`: `.nii.gz`
109+
`test.sh` will build the docker container (which contains the algorithm), provide the `test` folder as input to the docker container and run the algorithm. The output of the algorithm will be placed in the `output` directory. Tests will also be run to check if the algorithm provides the expected output.
110110

111+
Note: It is recommended to run this before you integrate your own algorithm into the template.
111112

112-
<!-- USAGE EXAMPLES -->
113113

114-
## Usage
114+
### Using the template
115+
To integrate your algorithm into this template, you need to modify the `predict` function of the `SynthradAlgorithm` in the `process.py` file.
116+
```{python}
117+
class SynthradAlgorithm(BaseSynthradAlgorithm):
118+
...
119+
120+
def predict(self, input_dict: Dict[str, sitk.Image]) -> sitk.Image:
121+
"""
122+
Your algorithm implementation.
123+
"""
124+
# Your code here
125+
return output_image
126+
```
127+
128+
You might need to load your models first before running the algorithm and this can be done in the `__init__` function of the `SynthradAlgorithm` class. For instance, to load a pytorch model,
129+
```{python}
130+
class SynthradAlgorithm(BaseSynthradAlgorithm):
131+
def __init__(self, *args, **kwargs):
132+
super().__init__(*args, **kwargs)
133+
134+
# Load the PyTorch model
135+
model_path = os.path.join(os.path.dirname(__file__), 'your_model.pt')
136+
self.model = torch.load(model_path)
137+
self.model.eval()
138+
```
139+
140+
### Making submissions to Task 1 and 2.
141+
Since the challenge contains two tasks, you will need to provide separate docker containers for each (even if you run the exact same algorithm on both). To configure which task your docker will be built for, we have provided a `.env` file. You can modify it before building the docker image and your docker will be built for the selected task.
142+
```
143+
TASK_TYPE="cbct" # Set to mri (Task 1) or cbct (Task 2)
144+
INPUT_FOLDER="/input" # Do not change unless you want to test locally
145+
```
146+
147+
Change the `TASK_TYPE` to "cbct" or "mri" depending on the task you want to make the submission for. Do not change the `INPUT_FOLDER` unless you are testing locally.
148+
149+
150+
### Building and exporting the docker container with your new algorithm!
151+
It is recommended to run `test.sh` first as it will ensure that your new algorithm always runs as expected.
115152

116-
1. Data is to be organized so that the input files to run the algorithm on are placed in the `test` folder in the same format as the dummy generated data. Images are to be placed in the `images` folder and `masks` are to be placed in the masks folder. Corresponding image and mask should have the same name
153+
1. Run the `export.sh` command. You can provide a name as the next argument to allow naming your docker containers.
154+
Example: `./export.sh cbct_docker`
117155

118-
2. Run `test.sh`
156+
2. You might need to wait a bit for this process to complete (depending on your model size and dependencies added by you) as it builds and saves the docker as `.tar.gz`. Once you have this `.tar.gz` file, you can submit it on the grand challenge portal in the SynthRAD submissions!
119157

120-
### Functions Descriptions
121158

122-
**test.sh**
159+
Video will be uploaded very soon on how you can submit it on the GC portal!
123160

124-
description:
125-
create the docker and run the algorithm-template
126-
127-
command line usage:
128-
./test.sh
161+
### Adding your own model files to the docker container
162+
This step requires a bit of familiarity with the docker ecosystem as you will need to edit the `Dockerfile` to do so. The models will be embedded into the docker container allowing the docker to run independently on any system!
129163

164+
As a start, you can copy model files into the docker by adding something like this into the `Dockerfile`,
165+
```
166+
COPY --chown=algorithm:algorithm your_model.pt /opt/algorithm/
167+
168+
```
169+
170+
Once you do this, `your_model.pt` should be accessible in the `___init___` function as described above.
171+
172+
173+
### Testing your algorithm locally.
174+
In order to first test your algorithm locally (without the docker build process etc. - significantly speeds up over multiple iterations),
175+
1. Configure `.env` for local mode by setting the `INPUT_FOLDER` to the path where you want to provide the inputs from. For instance, the `test` folder is a good starting place. But you could also provide your own data. (!!! NOTE: SET THE `INPUT_FOLDER` back to `/input` before your build the docker)
176+
177+
2. Run `python process.py` in an environment with all your dependencies installed.
178+
179+
180+
This should run your algorithm locally and allow you to test different iterations before making a docker container.
130181

131182

183+
### Reformatting your own data
184+
In the `setup` folder, the `create_dummy_data.py` gives an example of how the dummy data is created for the docker container. You can reformat your own data in accordance to be run by the docker container.
185+
186+
For the MRI task, this is how the data should be organized.
187+
```
188+
data
189+
├── images
190+
│ ├── body
191+
│ │ └── 1BAxxx.nii.gz
192+
│ │ └── ...
193+
│ ├── mri
194+
│ │ └── 1BAxxx.nii.gz
195+
│ │ └── ...
196+
197+
```
198+
199+
Similarly for the CBCT task,
200+
```
201+
data
202+
├── images
203+
│ ├── body
204+
│ │ └── 1BAxxx.nii.gz
205+
│ │ └── ...
206+
│ ├── cbct
207+
│ │ └── 1BAxxx.nii.gz
208+
│ │ └── ...
209+
210+
```
211+
132212
<!-- ROADMAP -->
133213
## Roadmap
134214

@@ -171,13 +251,13 @@ Project Link: [https://github.com/SynthRAD2023/algorithm-template](https://githu
171251
<!-- MARKDOWN LINKS & IMAGES -->
172252
<!-- https://www.markdownguide.org/basic-syntax/
173253
#reference-style-links -->
174-
[contributors-shield]: https://img.shields.io/github/contributors/SynthRAD2023/repo.svg?style=flat-square
175-
[contributors-url]: https://github.com/SynthRAD2023/repo/graphs/contributors
176-
[forks-shield]: https://img.shields.io/github/forks/SynthRAD2023/repo.svg?style=flat-square
177-
[forks-url]: https://github.com/SynthRAD2023/repo/network/members
178-
[stars-shield]: https://img.shields.io/github/stars/SynthRAD2023/repo.svg?style=flat-square
179-
[stars-url]: https://github.com/SynthRAD2023/repo/stargazers
180-
[issues-shield]: https://img.shields.io/github/issues/SynthRAD2023/repo.svg?style=flat-square
181-
[issues-url]: https://github.com/SynthRAD2023/repo/issues
182-
[license-shield]: https://img.shields.io/github/license/SynthRAD2023/repo.svg?style=flat-square
183-
[license-url]: https://github.com/SynthRAD2023/repo/blob/master/LICENSE.txt
254+
[contributors-shield]: https://img.shields.io/github/contributors/SynthRAD2023/algorithm-template.svg?style=flat-square
255+
[contributors-url]: https://github.com/SynthRAD2023/algorithm-template/graphs/contributors
256+
[forks-shield]: https://img.shields.io/github/forks/SynthRAD2023/algorithm-template.svg?style=flat-square
257+
[forks-url]: https://github.com/SynthRAD2023/algorithm-template/network/members
258+
[stars-shield]: https://img.shields.io/github/stars/SynthRAD2023/algorithm-template.svg?style=flat-square
259+
[stars-url]: https://github.com/SynthRAD2023/algorithm-template/stargazers
260+
[issues-shield]: https://img.shields.io/github/issues/SynthRAD2023/algorithm-template.svg?style=flat-square
261+
[issues-url]: https://github.com/SynthRAD2023/algorithm-template/issues
262+
[license-shield]: https://img.shields.io/github/license/SynthRAD2023/algorithm-template.svg?style=flat-square
263+
[license-url]: https://github.com/SynthRAD2023/algorithm-template/blob/master/LICENSE.txt

export.sh

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
#!/usr/bin/env bash
22

3+
# Set a default value for algorithm_name
4+
algorithm_name="synthrad_algorithm"
5+
# Check if a command-line argument is specified, and use it as the algorithm_name
6+
if [ ! -z "$1" ]; then
7+
algorithm_name="$1"
8+
fi
9+
310
./build.sh
411

5-
docker save synthrad_algorithm | gzip -c > synthrad_algorithm.tar.gz
12+
docker save synthrad_algorithm | gzip -c > "${algorithm_name}.tar.gz"

0 commit comments

Comments
 (0)