Skip to content

Commit

Permalink
Merge pull request #54 from BrainLesion/53-split-post-op-glioma-algor…
Browse files Browse the repository at this point in the history
…ithms-into-own-class

53 split post op glioma algorithms into own class
  • Loading branch information
neuronflow authored Jan 3, 2025
2 parents b650646 + 9fa1295 commit 197ae31
Show file tree
Hide file tree
Showing 9 changed files with 177 additions and 87 deletions.
55 changes: 41 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,17 @@ pip install brats
## Available Algorithms and Usage

### Segmentation
<details open>
<details>

<summary> <strong> Adult Glioma Segmentation </strong> </summary>
<summary> <strong> Adult Glioma Segmentation (Pre Treatment) </strong> </summary>
<br>


```python
from brats import AdultGliomaSegmenter
from brats.constants import AdultGliomaAlgorithms
from brats import AdultGliomaPreTreatmentSegmenter
from brats.constants import AdultGliomaPreTreatmentAlgorithms

segmenter = AdultGliomaSegmenter(algorithm=AdultGliomaAlgorithms.BraTS23_1, cuda_devices="0")
segmenter = AdultGliomaPreTreatmentSegmenter(algorithm=AdultGliomaPreTreatmentAlgorithms.BraTS23_1, cuda_devices="0")
# these parameters are optional, by default the winning algorithm of 2023 will be used on cuda:0
segmenter.infer_single(
t1c="path/to/t1c.nii.gz",
Expand All @@ -61,16 +61,43 @@ segmenter.infer_single(
)
```

**Class:** `brats.AdultGliomaSegmenter` ([Docs](https://brats.readthedocs.io/en/latest/core/segmentation_algorithms.html#brats.core.segmentation_algorithms.AdultGliomaSegmenter))
**Class:** `brats.AdultGliomaPreTreatmentSegmenter` ([Docs](https://brats.readthedocs.io/en/latest/core/segmentation_algorithms.html#brats.core.segmentation_algorithms.AdultGliomaPreTreatmentSegmenter))

| Year | Rank | Author | Paper | CPU Support | Key Enum |
| ---- | ---- | --------------------------------- | ------------------------------------------ | ----------- | ------------------------------------------------------------------------------------------------------------------------------------ |
| 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.constants.**AdultGliomaPreTreatmentAlgorithms**.BraTS23_1) |
| 2023 | 2nd | _Andriy Myronenko, et al._ | N/A | &#x274C; | [BraTS23_2](https://brats.readthedocs.io/en/latest/utils/utils.html#brats.constants.**AdultGliomaPreTreatmentAlgorithms**.BraTS23_2) |
| 2023 | 3rd | _Fadillah Adamsyah Maani, et al._ | N/A | &#x274C; | [BraTS23_3](https://brats.readthedocs.io/en/latest/utils/utils.html#brats.constants.**AdultGliomaPreTreatmentAlgorithms**.BraTS23_3) |

</details>

<details>
<summary> <strong> Adult Glioma Segmentation Post Treatment </strong> </summary>
<br>


```python
from brats import AdultGliomaPostTreatmentSegmenter
from brats.constants import AdultGliomaPostTreatmentAlgorithms

segmenter = AdultGliomaPostTreatmentSegmenter(algorithm=AdultGliomaPostTreatmentAlgorithms.BraTS23_1, cuda_devices="0")
# these parameters are optional, by default the winning algorithm of 2024 will be used on cuda:0
segmenter.infer_single(
t1c="path/to/t1c.nii.gz",
t1n="path/to/t1n.nii.gz",
t2f="path/to/t2f.nii.gz",
t2w="path/to/t2w.nii.gz",
output_file="segmentation.nii.gz",
)
```

**Class:** `brats.AdultGliomaPostTreatmentSegmenter` ([Docs](https://brats.readthedocs.io/en/latest/core/segmentation_algorithms.html#brats.core.segmentation_algorithms.AdultGliomaPostTreatmentSegmenter))

| Year | Rank | Author | Paper | CPU Support | Key Enum |
| ---- | ---- | --------------------------------- | ------------------------------------------ | ----------- | -------------------------------------------------------------------------------------------------------------------- |
| 2024 | 1st | _André Ferreira, et al._ | N/A | &#x274C; | [BraTS24_1](https://brats.readthedocs.io/en/latest/utils/utils.html#brats.constants.AdultGliomaAlgorithms.BraTS24_1) |
| 2024 | 2nd | _Team kimbab_ | N/A | &#x274C; | [BraTS24_2](https://brats.readthedocs.io/en/latest/utils/utils.html#brats.constants.AdultGliomaAlgorithms.BraTS24_2) |
| 2024 | 3rd | _Adrian Celaya_ | N/A | &#x2705; | [BraTS24_3](https://brats.readthedocs.io/en/latest/utils/utils.html#brats.constants.AdultGliomaAlgorithms.BraTS24_3) |
| 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.constants.AdultGliomaAlgorithms.BraTS23_1) |
| 2023 | 2nd | _Andriy Myronenko, et al._ | N/A | &#x274C; | [BraTS23_2](https://brats.readthedocs.io/en/latest/utils/utils.html#brats.constants.AdultGliomaAlgorithms.BraTS23_2) |
| 2023 | 3rd | _Fadillah Adamsyah Maani, et al._ | N/A | &#x274C; | [BraTS23_3](https://brats.readthedocs.io/en/latest/utils/utils.html#brats.constants.AdultGliomaAlgorithms.BraTS23_3) |
| Year | Rank | Author | Paper | CPU Support | Key Enum |
| ---- | ---- | ------------------------ | ----- | ----------- | --------------------------------------------------------------------------------------------------------------------------------- |
| 2024 | 1st | _André Ferreira, et al._ | N/A | &#x274C; | [BraTS24_1](https://brats.readthedocs.io/en/latest/utils/utils.html#brats.constants.AdultGliomaPostTreatmentAlgorithms.BraTS24_1) |
| 2024 | 2nd | _Team kimbab_ | N/A | &#x274C; | [BraTS24_2](https://brats.readthedocs.io/en/latest/utils/utils.html#brats.constants.AdultGliomaPostTreatmentAlgorithms.BraTS24_2) |
| 2024 | 3rd | _Adrian Celaya_ | N/A | &#x2705; | [BraTS24_3](https://brats.readthedocs.io/en/latest/utils/utils.html#brats.constants.AdultGliomaPostTreatmentAlgorithms.BraTS24_3) |

</details>

Expand Down
3 changes: 2 additions & 1 deletion brats/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from brats.core.inpainting_algorithms import Inpainter
from brats.core.segmentation_algorithms import (
AdultGliomaSegmenter,
AdultGliomaPostTreatmentSegmenter,
AdultGliomaPreTreatmentSegmenter,
AfricaSegmenter,
MeningiomaSegmenter,
MetastasesSegmenter,
Expand Down
15 changes: 12 additions & 3 deletions brats/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ class Algorithms(str, Enum):
pass


class AdultGliomaAlgorithms(Algorithms):
"""Constants for the available adult glioma segmentation algorithms."""
class AdultGliomaPostTreatmentAlgorithms(Algorithms):
"""Constants for the available adult glioma post treatment segmentation algorithms."""

BraTS24_1 = "BraTS24_1"
""" BraTS24 Adult Glioma Segmentation 1st place """
Expand All @@ -36,6 +36,10 @@ class AdultGliomaAlgorithms(Algorithms):
BraTS24_3 = "BraTS24_3"
""" BraTS24 Adult Glioma Segmentation 3rd place """


class AdultGliomaPreTreatmentAlgorithms(Algorithms):
"""Constants for the available adult glioma pre treatment segmentation algorithms."""

BraTS23_1 = "BraTS23_1"
"""BraTS23 Adult Glioma Segmentation 1st place (GPU only)"""
BraTS23_2 = "BraTS23_2"
Expand Down Expand Up @@ -145,7 +149,12 @@ class MissingMRIAlgorithms(Algorithms):
ADDITIONAL_FILES_FOLDER = DATA_DIR / "additional_files"

# META DATA FILE PATHS
ADULT_GLIOMA_SEGMENTATION_ALGORITHMS = META_DIR / "adult_glioma.yml"
ADULT_GLIOMA_PRE_TREATMENT_SEGMENTATION_ALGORITHMS = (
META_DIR / "adult_glioma_pre_treatment.yml"
)
ADULT_GLIOMA_POST_TREATMENT_SEGMENTATION_ALGORITHMS = (
META_DIR / "adult_glioma_post_treatment.yml"
)
MENINGIOMA_SEGMENTATION_ALGORITHMS = META_DIR / "meningioma.yml"
PEDIATRIC_SEGMENTATION_ALGORITHMS = META_DIR / "pediatric.yml"
AFRICA_SEGMENTATION_ALGORITHMS = META_DIR / "africa.yml"
Expand Down
39 changes: 32 additions & 7 deletions brats/core/segmentation_algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@

from brats.core.brats_algorithm import BraTSAlgorithm
from brats.constants import (
ADULT_GLIOMA_SEGMENTATION_ALGORITHMS,
ADULT_GLIOMA_POST_TREATMENT_SEGMENTATION_ALGORITHMS,
ADULT_GLIOMA_PRE_TREATMENT_SEGMENTATION_ALGORITHMS,
AFRICA_SEGMENTATION_ALGORITHMS,
MENINGIOMA_SEGMENTATION_ALGORITHMS,
METASTASES_SEGMENTATION_ALGORITHMS,
PEDIATRIC_SEGMENTATION_ALGORITHMS,
AdultGliomaAlgorithms,
AdultGliomaPostTreatmentAlgorithms,
AdultGliomaPreTreatmentAlgorithms,
AfricaAlgorithms,
Algorithms,
MeningiomaAlgorithms,
Expand Down Expand Up @@ -184,24 +186,47 @@ def infer_batch(
)


class AdultGliomaSegmenter(SegmentationAlgorithm):
"""Provides algorithms to perform tumor segmentation on adult glioma MRI data.
class AdultGliomaPreTreatmentSegmenter(SegmentationAlgorithm):
"""Provides algorithms to perform tumor segmentation on adult glioma pre treatment MRI data.
Args:
algorithm (AdultGliomaAlgorithms, optional): Select an algorithm. Defaults to AdultGliomaAlgorithms.BraTS23_1.
algorithm (AdultGliomaPreTreatmentAlgorithms, optional): Select an algorithm. Defaults to AdultGliomaPreTreatmentAlgorithms.BraTS23_1.
cuda_devices (Optional[str], optional): Which cuda devices to use. Defaults to "0".
force_cpu (bool, optional): Execution will default to GPU, this flag allows forced CPU execution if the algorithm is compatible. Defaults to False.
"""

def __init__(
self,
algorithm: AdultGliomaAlgorithms = AdultGliomaAlgorithms.BraTS23_1,
algorithm: AdultGliomaPreTreatmentAlgorithms = AdultGliomaPreTreatmentAlgorithms.BraTS23_1,
cuda_devices: Optional[str] = "0",
force_cpu: bool = False,
):
super().__init__(
algorithm=algorithm,
algorithms_file_path=ADULT_GLIOMA_SEGMENTATION_ALGORITHMS,
algorithms_file_path=ADULT_GLIOMA_PRE_TREATMENT_SEGMENTATION_ALGORITHMS,
cuda_devices=cuda_devices,
force_cpu=force_cpu,
)


class AdultGliomaPostTreatmentSegmenter(SegmentationAlgorithm):
"""Provides algorithms to perform tumor segmentation on adult glioma post treatment MRI data.
Args:
algorithm (AdultGliomaPostTreatmentAlgorithms, optional): Select an algorithm. Defaults to AdultGliomaPostTreatmentAlgorithms.BraTS24_1.
cuda_devices (Optional[str], optional): Which cuda devices to use. Defaults to "0".
force_cpu (bool, optional): Execution will default to GPU, this flag allows forced CPU execution if the algorithm is compatible. Defaults to False.
"""

def __init__(
self,
algorithm: AdultGliomaPostTreatmentAlgorithms = AdultGliomaPostTreatmentAlgorithms.BraTS24_1,
cuda_devices: Optional[str] = "0",
force_cpu: bool = False,
):
super().__init__(
algorithm=algorithm,
algorithms_file_path=ADULT_GLIOMA_POST_TREATMENT_SEGMENTATION_ALGORITHMS,
cuda_devices=cuda_devices,
force_cpu=force_cpu,
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
constants:
input_name_schema: &input_name_schema "BraTS-GLI-{id:05d}-000"
challenge: &challenge "Adult Glioma Segmentation"
challenge: &challenge "Adult Glioma Segmentation (Post Treatment)"
years:
2024: &year_2024 2024
2023: &year_2023 2023
ranks:
1st: &rank_1 1st
2nd: &rank_2 2nd
Expand Down Expand Up @@ -61,51 +60,4 @@ algorithms:
additional_files:
record_id: "14411467"
param_name: ["mist_models", "mist_config", "mist_dataset"]
param_path: ["models", "config.json", "dataset.json"]

##### 2023 #####

BraTS23_1:
meta:
authors: André Ferreira, et al.
paper: https://arxiv.org/abs/2402.17317v1
challenge: *challenge
rank: *rank_1
year: *year_2023
run_args:
docker_image: brainles/brats23_faking_it:latest
input_name_schema: *input_name_schema
requires_root: true
parameters_file: false
shm_size: "2gb"

BraTS23_2:
meta:
authors: Andriy Myronenko, et al.
paper: N/A
challenge: *challenge
rank: *rank_2
year: *year_2023
run_args:
docker_image: brainles/brats23_nvauto:latest
input_name_schema: *input_name_schema
requires_root: true
parameters_file: true
shm_size: "32gb"

BraTS23_3:
meta:
authors: Fadillah Adamsyah Maani, et al.
paper: N/A
challenge: *challenge
rank: *rank_3
year: *year_2023
run_args:
docker_image: brainles/brats23_biomedmbz:latest
input_name_schema: *input_name_schema
requires_root: false
parameters_file: true
shm_size: "2gb"
additional_files:
record_id: "11573315"
param_name: ["checkpoint_dir"]
param_path: ["models", "config.json", "dataset.json"]
59 changes: 59 additions & 0 deletions brats/data/meta/adult_glioma_pre_treatment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
constants:
input_name_schema: &input_name_schema "BraTS-GLI-{id:05d}-000"
challenge: &challenge "Adult Glioma Segmentation (Pre Treatment)"
years:
2023: &year_2023 2023
ranks:
1st: &rank_1 1st
2nd: &rank_2 2nd
3rd: &rank_3 3rd


algorithms:

##### 2023 #####

BraTS23_1:
meta:
authors: André Ferreira, et al.
paper: https://arxiv.org/abs/2402.17317v1
challenge: *challenge
rank: *rank_1
year: *year_2023
run_args:
docker_image: brainles/brats23_faking_it:latest
input_name_schema: *input_name_schema
requires_root: true
parameters_file: false
shm_size: "2gb"

BraTS23_2:
meta:
authors: Andriy Myronenko, et al.
paper: N/A
challenge: *challenge
rank: *rank_2
year: *year_2023
run_args:
docker_image: brainles/brats23_nvauto:latest
input_name_schema: *input_name_schema
requires_root: true
parameters_file: true
shm_size: "32gb"

BraTS23_3:
meta:
authors: Fadillah Adamsyah Maani, et al.
paper: N/A
challenge: *challenge
rank: *rank_3
year: *year_2023
run_args:
docker_image: brainles/brats23_biomedmbz:latest
input_name_schema: *input_name_schema
requires_root: false
parameters_file: true
shm_size: "2gb"
additional_files:
record_id: "11573315"
param_name: ["checkpoint_dir"]
2 changes: 1 addition & 1 deletion docs/source/core/segmentation_algorithms.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Segmentation Algorithms
========================

The following classes provide segmentation algorithms from several BraTS challenges.
The following classes provide algorithms from several BraTS segmentation challenges.

.. automodule:: brats.core.segmentation_algorithms
4 changes: 2 additions & 2 deletions tests/core/test_brats_algorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import tempfile
import shutil

from brats import AdultGliomaSegmenter
from brats import AdultGliomaPostTreatmentSegmenter
from brats.constants import OUTPUT_NAME_SCHEMA


Expand All @@ -31,7 +31,7 @@ def setUp(self):
file.touch()

# the core inference method is the same for all segmentation and inpainting algorithms, we use AdultGliomaSegmenter as an example during testing
self.segmenter = AdultGliomaSegmenter()
self.segmenter = AdultGliomaPostTreatmentSegmenter()

def tearDown(self):
# Remove the temporary directory after the test
Expand Down
Loading

0 comments on commit 197ae31

Please sign in to comment.