Skip to content

Commit 45aeb9e

Browse files
authored
Merge pull request #47 from BrainLesion/43-add-2024-inpainting-algorithms
43 add 2024 inpainting algorithms
2 parents 4e2d4c5 + 5bd4c2c commit 45aeb9e

15 files changed

+217
-46
lines changed

README.md

Lines changed: 105 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pip install brats
2626
> [!IMPORTANT]
2727
> To run `brats` you require a Docker installation. <br>
2828
> Many algorithms also require GPU support (NVIDIA Docker). <br>
29-
> In case you do not have access to a Cuda-capable GPU, the overview tables in the [Algorithms](#algorithms) section indicate which algorithms are CPU compatible.
29+
> In case you do not have access to a Cuda-capable GPU, the overview tables in the [Available Algorithms and Usage](#available-algorithms-and-Usage) section indicate which algorithms are CPU compatible.
3030
3131

3232

@@ -36,13 +36,19 @@ pip install brats
3636
- **Docker**: Installation instructions on the official [website](https://docs.docker.com/get-docker/)
3737
- **NVIDIA Container Toolkit**: Refer to the [NVIDIA install guide](https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/latest/install-guide.html) and the official [GitHub page](https://github.com/NVIDIA/nvidia-container-toolkit)
3838

39-
## Use Cases and Tutorials
4039

41-
A minimal example to create a segmentation could look like this:
40+
## Available Algorithms and Usage
41+
42+
### Segmentation
43+
<details open>
44+
45+
<summary> <strong> Adult Glioma Segmentation </strong> </summary>
46+
<br>
47+
4248

4349
```python
4450
from brats import AdultGliomaSegmenter
45-
from brats.utils.constants import AdultGliomaAlgorithms
51+
from brats.constants import AdultGliomaAlgorithms
4652

4753
segmenter = AdultGliomaSegmenter(algorithm=AdultGliomaAlgorithms.BraTS23_1, cuda_devices="0")
4854
# these parameters are optional, by default the winning algorithm will be used on cuda:0
@@ -55,19 +61,10 @@ segmenter.infer_single(
5561
)
5662
```
5763

58-
For more examples and details please refer to our extensive Notebook tutorials here [NBViewer](https://nbviewer.org/github/BrainLesion/tutorials/blob/main/BraTS/tutorial.ipynb) ([GitHub](https://github.com/BrainLesion/tutorials/blob/main/BraTS/tutorial.ipynb)). For the best experience open the notebook in Colab.
59-
60-
## Algorithms
61-
62-
<details open>
63-
64-
<summary> <strong> Adult Glioma Segmentation </strong> </summary>
65-
<br>
66-
6764
**Class:** `brats.AdultGliomaSegmenter` ([Docs](https://brats.readthedocs.io/en/latest/core/segmentation_algorithms.html#brats.core.segmentation_algorithms.AdultGliomaSegmenter))
6865

69-
| Year | Rank | Author | Paper | CPU Support | Key Enum |
70-
| ---- | ---- | --------------------------------- | ------------------------------------------ | ----------- | ------------------------------------------------------------------------------------------------------------------------ |
66+
| Year | Rank | Author | Paper | CPU Support | Key Enum |
67+
| ---- | ---- | --------------------------------- | ------------------------------------------ | ----------- | -------------------------------------------------------------------------------------------------------------------------- |
7168
| 2023 | 1st | _André Ferreira, et al._ | [Link](https://arxiv.org/abs/2402.17317v1) | &#x274C; | [BraTS23_1](https://brats.readthedocs.io/en/latest/utils/utils.html#brats.utils.constants.AdultGliomaAlgorithms.BraTS23_1) |
7269
| 2023 | 2nd | _Andriy Myronenko, et al._ | N/A | &#x274C; | [BraTS23_2](https://brats.readthedocs.io/en/latest/utils/utils.html#brats.utils.constants.AdultGliomaAlgorithms.BraTS23_2) |
7370
| 2023 | 3rd | _Fadillah Adamsyah Maani, et al._ | N/A | &#x274C; | [BraTS23_3](https://brats.readthedocs.io/en/latest/utils/utils.html#brats.utils.constants.AdultGliomaAlgorithms.BraTS23_3) |
@@ -78,10 +75,25 @@ For more examples and details please refer to our extensive Notebook tutorials h
7875
<summary> <strong> BraTS-Africa Segmentation </strong> </summary>
7976
<br>
8077

78+
```python
79+
from brats import AfricaSegmenter
80+
from brats.constants import AfricaAlgorithms
81+
82+
segmenter = AfricaSegmenter(algorithm=AfricaAlgorithms.BraTS23_1, cuda_devices="0")
83+
# these parameters are optional, by default the winning algorithm will be used on cuda:0
84+
segmenter.infer_single(
85+
t1c="path/to/t1c.nii.gz",
86+
t1n="path/to/t1n.nii.gz",
87+
t2f="path/to/t2f.nii.gz",
88+
t2w="path/to/t2w.nii.gz",
89+
output_file="segmentation.nii.gz",
90+
)
91+
```
92+
8193
**Class:** `brats.AfricaSegmenter` ([Docs](https://brats.readthedocs.io/en/latest/core/segmentation_algorithms.html#brats.core.segmentation_algorithms.AfricaSegmenter))
8294

83-
| Year | Rank | Author | Paper | CPU Support | Key Enum |
84-
| ---- | ---- | -------------------------- | ----- | ----------- | ------------------------------------------------------------------------------------------------------------------- |
95+
| Year | Rank | Author | Paper | CPU Support | Key Enum |
96+
| ---- | ---- | -------------------------- | ----- | ----------- | --------------------------------------------------------------------------------------------------------------------- |
8597
| 2023 | 1st | _Andriy Myronenko, et al._ | TODO | &#x274C; | [BraTS23_1](https://brats.readthedocs.io/en/latest/utils/utils.html#brats.utils.constants.AfricaAlgorithms.BraTS23_1) |
8698
| 2023 | 2nd | _Alyssa R Amod, et al._ | N/A | &#x274C; | [BraTS23_2](https://brats.readthedocs.io/en/latest/utils/utils.html#brats.utils.constants.AfricaAlgorithms.BraTS23_2) |
8799
| 2023 | 3rd | _Ziyan Huang, et al._ | N/A | &#x2705; | [BraTS23_3](https://brats.readthedocs.io/en/latest/utils/utils.html#brats.utils.constants.AfricaAlgorithms.BraTS23_3) |
@@ -92,10 +104,25 @@ For more examples and details please refer to our extensive Notebook tutorials h
92104
<summary> <strong> Meningioma Segmentation </strong> </summary>
93105
<br>
94106

107+
```python
108+
from brats import MeningiomaSegmenter
109+
from brats.constants import MeningiomaAlgorithms
110+
111+
segmenter = MeningiomaSegmenter(algorithm=MeningiomaAlgorithms.BraTS23_1, cuda_devices="0")
112+
# these parameters are optional, by default the winning algorithm will be used on cuda:0
113+
segmenter.infer_single(
114+
t1c="path/to/t1c.nii.gz",
115+
t1n="path/to/t1n.nii.gz",
116+
t2f="path/to/t2f.nii.gz",
117+
t2w="path/to/t2w.nii.gz",
118+
output_file="segmentation.nii.gz",
119+
)
120+
```
121+
95122
**Class:** `brats.MeningiomaSegmenter` ([Docs](https://brats.readthedocs.io/en/latest/core/segmentation_algorithms.html#brats.core.segmentation_algorithms.MeningiomaSegmenter))
96123

97-
| Year | Rank | Author | Paper | CPU Support | Key Enum |
98-
| ---- | ---- | -------------------------- | ----- | ----------- | ----------------------------------------------------------------------------------------------------------------------- |
124+
| Year | Rank | Author | Paper | CPU Support | Key Enum |
125+
| ---- | ---- | -------------------------- | ----- | ----------- | ------------------------------------------------------------------------------------------------------------------------- |
99126
| 2023 | 1st | _Andriy Myronenko, et al._ | N/A | &#x274C; | [BraTS23_1](https://brats.readthedocs.io/en/latest/utils/utils.html#brats.utils.constants.MeningiomaAlgorithms.BraTS23_1) |
100127
| 2023 | 2nd | _Ziyan Huang, et al._ | N/A | &#x2705; | [BraTS23_2](https://brats.readthedocs.io/en/latest/utils/utils.html#brats.utils.constants.MeningiomaAlgorithms.BraTS23_2) |
101128
| 2023 | 3rd | _Zhifan Jiang et al._ | N/A | &#x274C; | [BraTS23_3](https://brats.readthedocs.io/en/latest/utils/utils.html#brats.utils.constants.MeningiomaAlgorithms.BraTS23_3) |
@@ -106,10 +133,25 @@ For more examples and details please refer to our extensive Notebook tutorials h
106133
<summary> <strong> Brain Metastases Segmentation </strong> </summary>
107134
<br>
108135

136+
```python
137+
from brats import MetastasesSegmenter
138+
from brats.constants import MetastasesAlgorithms
139+
140+
segmenter = MetastasesSegmenter(algorithm=MetastasesAlgorithms.BraTS23_1, cuda_devices="0")
141+
# these parameters are optional, by default the winning algorithm will be used on cuda:0
142+
segmenter.infer_single(
143+
t1c="path/to/t1c.nii.gz",
144+
t1n="path/to/t1n.nii.gz",
145+
t2f="path/to/t2f.nii.gz",
146+
t2w="path/to/t2w.nii.gz",
147+
output_file="segmentation.nii.gz",
148+
)
149+
```
150+
109151
**Class:** `brats.MetastasesSegmenter` ([Docs](https://brats.readthedocs.io/en/latest/core/segmentation_algorithms.html#brats.core.segmentation_algorithms.MetastasesSegmenter))
110152

111-
| Year | Rank | Author | Paper | CPU Support | Key Enum |
112-
| ---- | ---- | -------------------------- | ----- | ----------- | ----------------------------------------------------------------------------------------------------------------------- |
153+
| Year | Rank | Author | Paper | CPU Support | Key Enum |
154+
| ---- | ---- | -------------------------- | ----- | ----------- | ------------------------------------------------------------------------------------------------------------------------- |
113155
| 2023 | 1st | _Andriy Myronenko, et al._ | N/A | &#x274C; | [BraTS23_1](https://brats.readthedocs.io/en/latest/utils/utils.html#brats.utils.constants.MetastasesAlgorithms.BraTS23_1) |
114156
| 2023 | 2nd | _Siwei Yang, et al._ | N/A | &#x274C; | [BraTS23_2](https://brats.readthedocs.io/en/latest/utils/utils.html#brats.utils.constants.MetastasesAlgorithms.BraTS23_2) |
115157
| 2023 | 3rd | _Ziyan Huang, et al._ | N/A | &#x2705; | [BraTS23_3](https://brats.readthedocs.io/en/latest/utils/utils.html#brats.utils.constants.MetastasesAlgorithms.BraTS23_3) |
@@ -120,32 +162,66 @@ For more examples and details please refer to our extensive Notebook tutorials h
120162
<summary> <strong> Pediatric Segmentation </strong> </summary>
121163
<br>
122164

165+
```python
166+
from brats import PediatricSegmenter
167+
from brats.constants import PediatricAlgorithms
168+
169+
segmenter = PediatricSegmenter(algorithm=PediatricAlgorithms.BraTS23_1, cuda_devices="0")
170+
# these parameters are optional, by default the winning algorithm will be used on cuda:0
171+
segmenter.infer_single(
172+
t1c="path/to/t1c.nii.gz",
173+
t1n="path/to/t1n.nii.gz",
174+
t2f="path/to/t2f.nii.gz",
175+
t2w="path/to/t2w.nii.gz",
176+
output_file="segmentation.nii.gz",
177+
)
178+
```
179+
123180
**Class:** `brats.PediatricSegmenter` ([Docs](https://brats.readthedocs.io/en/latest/core/segmentation_algorithms.html#brats.core.segmentation_algorithms.PediatricSegmenter))
124181

125-
| Year | Rank | Author | Paper | CPU Support | Key Enum |
126-
| ---- | ---- | -------------------------- | ----- | ----------- | ---------------------------------------------------------------------------------------------------------------------- |
182+
| Year | Rank | Author | Paper | CPU Support | Key Enum |
183+
| ---- | ---- | -------------------------- | ----- | ----------- | ------------------------------------------------------------------------------------------------------------------------ |
127184
| 2023 | 1st | _Zhifan Jiang et al._ | N/A | &#x274C; | [BraTS23_1](https://brats.readthedocs.io/en/latest/utils/utils.html#brats.utils.constants.PediatricAlgorithms.BraTS23_1) |
128185
| 2023 | 2nd | _Andriy Myronenko, et al._ | N/A | &#x274C; | [BraTS23_2](https://brats.readthedocs.io/en/latest/utils/utils.html#brats.utils.constants.PediatricAlgorithms.BraTS23_2) |
129186
| 2023 | 3rd | _Yubo Zhou_ | N/A | &#x274C; | [BraTS23_3](https://brats.readthedocs.io/en/latest/utils/utils.html#brats.utils.constants.PediatricAlgorithms.BraTS23_3) |
130187

131188
</details>
132189

133-
---
190+
### Inpainting
134191

135192
<details>
136193
<summary> <strong> Inpainting </strong> </summary>
137194
<br>
138195

196+
```python
197+
from brats import Inpainter
198+
from brats.constants import InpaintingAlgorithms
199+
200+
inpainter = Inpainter(algorithm=InpaintingAlgorithms.BraTS24_1, cuda_devices="0")
201+
inpainter.infer_single(
202+
t1n="path/to/voided_t1n.nii.gz",
203+
mask="path/to/mask.nii.gz",
204+
output_file="inpainting.nii.gz",
205+
)
206+
```
207+
139208
**Class:** `brats.Inpainter` ([Docs](https://brats.readthedocs.io/en/latest/core/inpainting_algorithms.html#brats.core.inpainting_algorithms.Inpainter))
140209

141-
| Year | Rank | Author | Paper | CPU Support | Key Enum |
142-
| ---- | ---- | ----------------------- | ----- | ----------- | ----------------------------------------------------------------------------------------------------------------------- |
143-
| 2023 | 1st | _Juexin Zhang, et al._ | N/A | &#x2705; | [BraTS23_1](https://brats.readthedocs.io/en/latest/utils/utils.html#brats.utils.constants.InpaintingAlgorithms.BraTS23_1) |
144-
| 2023 | 2nd | _Alicia Durrer, et al._ | N/A | &#x274C; | [BraTS23_2](https://brats.readthedocs.io/en/latest/utils/utils.html#brats.utils.constants.InpaintingAlgorithms.BraTS23_2) |
145-
| 2023 | 3rd | _Jiayu Huo, et al._ | N/A | &#x2705; | [BraTS23_3](https://brats.readthedocs.io/en/latest/utils/utils.html#brats.utils.constants.InpaintingAlgorithms.BraTS23_3) |
210+
| Year | Rank | Author | Paper | CPU Support | Key Enum |
211+
| ---- | ---- | ---------------------------------- | ----- | ----------- | ------------------------------------------------------------------------------------------------------------------------- |
212+
| 2024 | 1st | _Ke Chen, Juexin Zhang, Ying Weng_ | N/A | &#x2705; | [BraTS24_1](https://brats.readthedocs.io/en/latest/utils/utils.html#brats.utils.constants.InpaintingAlgorithms.BraTS24_1) |
213+
| 2024 | 2nd | _André Ferreira, et al._ | N/A | &#x274C; | [BraTS24_2](https://brats.readthedocs.io/en/latest/utils/utils.html#brats.utils.constants.InpaintingAlgorithms.BraTS24_2) |
214+
| 2024 | 3rd | _Team SMINT_ | N/A | &#x274C; | [BraTS24_3](https://brats.readthedocs.io/en/latest/utils/utils.html#brats.utils.constants.InpaintingAlgorithms.BraTS24_3) |
215+
| 2023 | 1st | _Juexin Zhang, et al._ | N/A | &#x2705; | [BraTS23_1](https://brats.readthedocs.io/en/latest/utils/utils.html#brats.utils.constants.InpaintingAlgorithms.BraTS23_1) |
216+
| 2023 | 2nd | _Alicia Durrer, et al._ | N/A | &#x274C; | [BraTS23_2](https://brats.readthedocs.io/en/latest/utils/utils.html#brats.utils.constants.InpaintingAlgorithms.BraTS23_2) |
217+
| 2023 | 3rd | _Jiayu Huo, et al._ | N/A | &#x2705; | [BraTS23_3](https://brats.readthedocs.io/en/latest/utils/utils.html#brats.utils.constants.InpaintingAlgorithms.BraTS23_3) |
146218

147219
</details>
148220

221+
>[!TIP]
222+
>For a full notebook example with more details please check here:
223+
> [![nbviewer](https://raw.githubusercontent.com/jupyter/design/master/logos/Badges/nbviewer_badge.svg)](https://nbviewer.org/github/BrainLesion/tutorials/blob/main/BraTS/tutorial.ipynb)
224+
149225
## Citation
150226

151227
If you use BraTS in your research, please cite it to support the development!

brats/utils/constants.py renamed to brats/constants.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,16 +81,22 @@ class MetastasesAlgorithms(Algorithms):
8181
class InpaintingAlgorithms(Algorithms):
8282
"""Constants for the available BraTS Inpainting algorithms."""
8383

84+
BraTS24_1 = "BraTS24_1"
85+
""" BraTS24 Inpainting 1st place """
86+
BraTS24_2 = "BraTS24_2"
87+
""" BraTS24 Inpainting 2nd place """
88+
BraTS24_3 = "BraTS24_3"
89+
""" BraTS24 Inpainting 3rd place """
8490
BraTS23_1 = "BraTS23_1"
85-
"""BraTS23 Inpainting 1st place (GPU only)"""
91+
""" BraTS23 Inpainting 1st place """
8692
BraTS23_2 = "BraTS23_2"
87-
"""BraTS23 Inpainting 2nd place (GPU only) (Very Slow)"""
93+
""" BraTS23 Inpainting 2nd place (Very Slow) """
8894
BraTS23_3 = "BraTS23_3"
89-
"""BraTS23 Inpainting 3rd place (GPU only)"""
95+
""" BraTS23 Inpainting 3rd place """
9096

9197

9298
# DIRECTORIES
93-
DATA_DIR = Path(__file__).parent.parent / "data"
99+
DATA_DIR = Path(__file__).parent / "data"
94100
META_DIR = DATA_DIR / "meta"
95101
PARAMETERS_DIR = DATA_DIR / "parameters"
96102
ADDITIONAL_FILES_FOLDER = DATA_DIR / "additional_files"

brats/core/brats_algorithm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
from brats.core.docker import run_container
1212
from brats.utils.algorithm_config import load_algorithms
13-
from brats.utils.constants import OUTPUT_NAME_SCHEMA, Algorithms, Task
13+
from brats.constants import OUTPUT_NAME_SCHEMA, Algorithms, Task
1414
from brats.utils.data_handling import InferenceSetup
1515

1616
# Remove the default logger and add one with level INFO

brats/core/docker.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from rich.progress import Progress
1616

1717
from brats.utils.algorithm_config import AlgorithmData
18-
from brats.utils.constants import DUMMY_PARAMETERS, PARAMETERS_DIR
18+
from brats.constants import DUMMY_PARAMETERS, PARAMETERS_DIR
1919
from brats.utils.exceptions import (
2020
AlgorithmNotCPUCompatibleException,
2121
BraTSContainerException,
@@ -231,7 +231,7 @@ def _observe_docker_output(container: docker.models.containers.Container) -> str
231231
# Wait for the container to finish
232232
exit_code = container.wait()
233233
container_output = "\n\r".join(
234-
[line.decode("utf-8") for line in container_output]
234+
[line.decode("utf-8", errors="replace") for line in container_output]
235235
)
236236
# Check if the container exited with an error
237237
if exit_code["StatusCode"] != 0:

brats/core/inpainting_algorithms.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from loguru import logger
99

1010
from brats.core.brats_algorithm import BraTSAlgorithm
11-
from brats.utils.constants import INPAINTING_ALGORITHMS, InpaintingAlgorithms, Task
11+
from brats.constants import INPAINTING_ALGORITHMS, InpaintingAlgorithms, Task
1212
from brats.utils.data_handling import input_sanity_check
1313

1414

brats/core/segmentation_algorithms.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from loguru import logger
99

1010
from brats.core.brats_algorithm import BraTSAlgorithm
11-
from brats.utils.constants import (
11+
from brats.constants import (
1212
ADULT_GLIOMA_SEGMENTATION_ALGORITHMS,
1313
AFRICA_SEGMENTATION_ALGORITHMS,
1414
MENINGIOMA_SEGMENTATION_ALGORITHMS,

brats/data/meta/inpainting.yml

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,57 @@
11
algorithms:
22

3+
######## 2024 Algorithms ########
4+
5+
BraTS24_1:
6+
meta:
7+
authors: Ke Chen, Juexin Zhang, Ying Weng
8+
paper: N/A
9+
challenge: BraTS24 Inpainting
10+
rank: 1st
11+
year: 2024
12+
run_args:
13+
docker_image: brainles/brats24_inpainting_ying_weng:latest
14+
input_name_schema: "BraTS-GLI-{id:05d}-000"
15+
requires_root: false
16+
parameters_file: true
17+
cpu_compatible: true
18+
weights:
19+
record_id: "14230865"
20+
param_name: "checkpoint_path"
21+
22+
BraTS24_2:
23+
meta:
24+
authors: André Ferreira, et al.
25+
paper: N/A
26+
challenge: BraTS24 Inpainting
27+
rank: 2nd
28+
year: 2024
29+
run_args:
30+
docker_image: brainles/brats24_inpainting_faking_it:latest
31+
input_name_schema: "BraTS-GLI-{id:05d}-000"
32+
requires_root: false
33+
parameters_file: false
34+
shm_size: "4gb"
35+
36+
BraTS24_3:
37+
meta:
38+
authors: Team SMINT
39+
paper: N/A
40+
challenge: BraTS24 Inpainting
41+
rank: 3rd
42+
year: 2024
43+
run_args:
44+
docker_image: brainles/brats24_inpainting_smint:latest
45+
input_name_schema: "BraTS-GLI-{id:05d}-000"
46+
requires_root: false
47+
parameters_file: true
48+
weights:
49+
record_id: "14231079"
50+
param_name: "weights"
51+
checkpoint_path: "savedmodel395000.pt"
52+
53+
######## 2023 Algorithms ########
54+
355
BraTS23_1:
456
meta:
557
authors: Juexin Zhang, et al.
@@ -10,7 +62,7 @@ algorithms:
1062
run_args:
1163
docker_image: brainles/brats23_inpainting_ying_weng:latest
1264
input_name_schema: "BraTS-GLI-{id:05d}-000"
13-
requires_root: true
65+
requires_root: false
1466
parameters_file: true
1567
cpu_compatible: true
1668
weights:

0 commit comments

Comments
 (0)