Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3 feature add brats africa segmentation algorithms #22

Merged
merged 17 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
70 changes: 55 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ pip install brats
### Docker and NVIDIA Container Toolkit Setup

To run `brats` you need a working Docker installation.
Most algorithms also require GPU support (NVIDIA Docker).
Most algorithms also require GPU support (NVIDIA Docker).

Installation instructions:
- **Docker**: Installation instructions on the official [website](https://docs.docker.com/get-docker/)
- **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)

- **Docker**: Installation instructions on the official [website](https://docs.docker.com/get-docker/)
- **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)

## Use Cases and Tutorials

Expand All @@ -51,32 +51,72 @@ segmenter.infer_single(
For more examples and details please refer to our extensive Notebook tutorials [**TODO**]

## Algorithms
| Challenge | Year | Position | Authors | Paper | CPU support |
|---|---|---|---|---|---|
| *Meningioma Segmentation* | 2023 | 1st | Andriy Myronenko, et al. | N/A | :heavy_multiplication_x: |
| | 2023 | 2nd | Ziyan Huang | N/A | :white_check_mark: |
| | 2023 | 3rd | Zhifan Jiang et al. | N/A | :heavy_multiplication_x: |
| *Pediatric Segmentation* | 2023 | 1st | Zhifan Jiang et al. | N/A | :heavy_multiplication_x: |
| | 2023 | 2nd | Andriy Myronenko, et al. | N/A | :heavy_multiplication_x: |
| | 2023 | 3rd | Yubo Zhou | N/A | :heavy_multiplication_x: |
| *Adult Glioma Segmentation* | 2023 | 1st | André Ferreira, et al. | [Link](https://arxiv.org/abs/2402.17317v1) | :heavy_multiplication_x: |
| | 2023 | 2nd | Andriy Myronenko, et al. | N/A | :heavy_multiplication_x: |
| | 2023 | 3rd | Fadillah Adamsyah Maani, et al. | N/A | :heavy_multiplication_x: |

<details open>

<summary> <strong> Adult Glioma Segmentation </strong> </summary>
<br>

| Year | Rank | Author | Paper | CPU Support |
| ---- | ---- | --------------------------------- | ------------------------------------------ | ----------- |
| 2023 | 1st | _André Ferreira, et al._ | [Link](https://arxiv.org/abs/2402.17317v1) | &#x274C; |
| 2023 | 2nd | _Andriy Myronenko, et al._ | N/A | &#x274C; |
| 2023 | 3rd | _Fadillah Adamsyah Maani, et al._ | N/A | &#x274C; |

</details>

<details>
<summary> <strong> BraTS-Africa Segmentation </strong> </summary>
<br>

| Year | Rank | Author | Paper | CPU Support |
| ---- | ---- | -------------------------- | ----- | ----------- |
| 2023 | 1st | _Andriy Myronenko, et al._ | N/A | &#x274C; |
| 2023 | 2nd | _Alyssa R Amod, et al._ | N/A | &#x274C; |
| 2023 | 3rd | _Ziyan Huang, et al._ | N/A | &#x2705; |

</details>

<details>
<summary> <strong> Meningioma Segmentation </strong> </summary>
<br>

| Year | Rank | Author | Paper | CPU Support |
| ---- | ---- | -------------------------- | ----- | ----------- |
| 2023 | 1st | _Andriy Myronenko, et al._ | N/A | &#x274C; |
| 2023 | 2nd | _Ziyan Huang_ | N/A | &#x2705; |
| 2023 | 3rd | _Zhifan Jiang et al._ | N/A | &#x274C; |

</details>

<details>
<summary> <strong> Pediatric Segmentation </strong> </summary>
<br>

| Year | Rank | Author | Paper | CPU Support |
| ---- | ---- | -------------------------- | ----- | ----------- |
| 2023 | 1st | _Zhifan Jiang et al._ | N/A | &#x274C; |
| 2023 | 2nd | _Andriy Myronenko, et al._ | N/A | &#x274C; |
| 2023 | 3rd | _Yubo Zhou_ | N/A | &#x274C; |

</details>

## Citation

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

```
TODO: citation will be added asap
```


## Contributing

We welcome all kinds of contributions from the community!

### Reporting Bugs, Feature Requests and Questions

Please open a new issue [here](https://github.com/BrainLesion/BraTS/issues).

### Code contributions

Nice to have you on board! Please have a look at our [CONTRIBUTING.md](CONTRIBUTING.md) file.
1 change: 1 addition & 0 deletions brats/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
AdultGliomaSegmenter,
MeningiomaSegmenter,
PediatricSegmenter,
AfricaSegmenter,
)
4 changes: 4 additions & 0 deletions brats/algorithm_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ class MetaData:
"""If available, a url to the paper of the algorithm"""
challenge: str
"""The challenge the algorithm was submitted to"""
rank: str
"""The rank of the algorithm in the challenge"""
year: int
"""The year the algorithm was submitted"""


@dataclass
Expand Down
67 changes: 56 additions & 11 deletions brats/algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@
from brats.algorithm_config import load_algorithms
from brats.constants import (
ADULT_GLIOMA_SEGMENTATION_ALGORITHMS,
AFRICA_SEGMENTATION_ALGORITHMS,
MENINGIOMA_SEGMENTATION_ALGORITHMS,
PEDIATRIC_SEGMENTATION_ALGORITHMS,
AdultGliomaAlgorithms,
Algorithms,
AfricaAlgorithms,
MeningiomaAlgorithms,
PediatricAlgorithms,
)
Expand Down Expand Up @@ -56,7 +58,7 @@ def __init__(
def _log_algorithm_info(self):
"""Log information about the selected algorithm."""
logger.opt(colors=True).info(
f"Running algorithm: <light-green>{self.algorithm.meta.challenge}</>"
f"Running algorithm: <light-green>{self.algorithm.meta.challenge} [{self.algorithm.meta.rank} place]</>"
)
logger.opt(colors=True).info(
f"<blue>(Paper)</> Consider citing the corresponding paper: {self.algorithm.meta.paper} by {self.algorithm.meta.authors}"
Expand All @@ -80,6 +82,24 @@ def _add_log_file_handler(self, log_file: Path | str) -> int:

return logger_id

def _cleanup(
self, temp_data_folder: Path, temp_output_folder: Path, logger_id: Optional[int]
) -> None:
try:
shutil.rmtree(temp_data_folder)
except PermissionError as e:
logger.warning(
f"Failed to remove temporary folder {temp_data_folder}. This is most likely caused by bad permission management of the docker container. \nError: {e}"
)
try:
shutil.rmtree(temp_output_folder)
except PermissionError as e:
logger.warning(
f"Failed to remove temporary folder {temp_output_folder}. This is most likely caused by bad permission management of the docker container. \nError: {e}"
)
if logger_id is not None:
logger.remove(logger_id)

def infer_single(
self,
t1c: Path | str,
Expand Down Expand Up @@ -137,10 +157,11 @@ def infer_single(
logger.info(f"Saved segmentation to: {output_file.absolute()}")

finally:
shutil.rmtree(temp_data_folder)
shutil.rmtree(temp_output_folder)
if log_file is not None:
logger.remove(logger_id)
self._cleanup(
temp_data_folder=temp_data_folder,
temp_output_folder=temp_output_folder,
logger_id=logger_id if log_file else None,
)

def infer_batch(
self,
Expand Down Expand Up @@ -207,10 +228,11 @@ def infer_batch(

logger.info(f"Saved results to: {output_folder.absolute()}")
finally:
shutil.rmtree(temp_data_folder)
shutil.rmtree(temp_output_folder)
if log_file:
logger.remove(logger_id)
self._cleanup(
temp_data_folder=temp_data_folder,
temp_output_folder=temp_output_folder,
logger_id=logger_id if log_file else None,
)


class AdultGliomaSegmenter(BraTSAlgorithm):
Expand Down Expand Up @@ -240,7 +262,7 @@ class MeningiomaSegmenter(BraTSAlgorithm):
"""Provides algorithms to perform tumor segmentation on adult meningioma MRI data.

Args:
algorithm (AdultGliomaAlgorithms, optional): Select an algorithm. Defaults to MeningiomaAlgorithms.BraTS23_1.
algorithm (MeningiomaAlgorithms, optional): Select an algorithm. Defaults to MeningiomaAlgorithms.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.
"""
Expand All @@ -263,7 +285,7 @@ class PediatricSegmenter(BraTSAlgorithm):
"""Provides algorithms to perform tumor segmentation on pediatric MRI data

Args:
algorithm (AdultGliomaAlgorithms, optional): Select an algorithm. Defaults to PediatricAlgorithms.BraTS23_1.
algorithm (PediatricAlgorithms, optional): Select an algorithm. Defaults to PediatricAlgorithms.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.
"""
Expand All @@ -280,3 +302,26 @@ def __init__(
cuda_devices=cuda_devices,
force_cpu=force_cpu,
)


class AfricaSegmenter(BraTSAlgorithm):
"""Provides algorithms to perform tumor segmentation on data from the BraTSAfrica challenge

Args:
algorithm (AfricaAlgorithms, optional): Select an algorithm. Defaults to AfricaAlgorithms.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: AfricaAlgorithms = AfricaAlgorithms.BraTS23_1,
cuda_devices: Optional[str] = "0",
force_cpu: bool = False,
):
super().__init__(
algorithm=algorithm,
algorithms_file_path=AFRICA_SEGMENTATION_ALGORITHMS,
cuda_devices=cuda_devices,
force_cpu=force_cpu,
)
12 changes: 9 additions & 3 deletions brats/algorithms/adult_glioma.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ algorithms:
meta:
authors: André Ferreira, et al.
paper: https://arxiv.org/abs/2402.17317v1
challenge: BraTS23 Adult Glioma Segmentation (1st place)
challenge: BraTS23 Adult Glioma Segmentation
rank: 1st
year: 2023
run_args:
docker_image: brainles/brats23_faking_it:latest
input_name_schema: "BraTS-GLI-{id:05d}-000"
Expand All @@ -16,7 +18,9 @@ algorithms:
meta:
authors: Andriy Myronenko, et al.
paper: N/A
challenge: BraTS23 Adult Glioma Segmentation (2nd place)
challenge: BraTS23 Adult Glioma Segmentation
rank: 2nd
year: 2023
run_args:
docker_image: brainles/brats23_nvauto:latest
input_name_schema: "BraTS-GLI-{id:05d}-000"
Expand All @@ -28,7 +32,9 @@ algorithms:
meta:
authors: Fadillah Adamsyah Maani, et al.
paper: N/A
challenge: BraTS23 Adult Glioma Segmentation (3rd place)
challenge: BraTS23 Adult Glioma Segmentation
rank: 3rd
year: 2023
run_args:
docker_image: brainles/brats23_biomedmbz:latest
input_name_schema: "BraTS-GLI-{id:05d}-000"
Expand Down
45 changes: 45 additions & 0 deletions brats/algorithms/africa.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
algorithms:

BraTS23_1:
meta:
authors: Andriy Myronenko, et al.
paper: TODO
challenge: BraTS23 BraTS-Africa Segmentation
rank: 1st
year: 2023
run_args:
docker_image: brainles/brats23_africa_nvauto:latest
input_name_schema: "BraTS-SSA-{id:05d}-000"
requires_root: true
parameters_file: true
shm_size: "32gb"

BraTS23_2:
meta:
authors: Alyssa R Amod, et al.
paper: N/A
challenge: BraTS23 BraTS-Africa Segmentation
rank: 2nd
year: 2023
run_args:
docker_image: brainles/brats23_africa_sparkunn:latest
input_name_schema: "BraTS-SSA-{id:05d}-000"
requires_root: false
parameters_file: true
weights:
record_id: "13373752"
param_name: "ckpts_path"
BraTS23_3:
meta:
authors: Ziyan Huang, et al.
paper: N/A
challenge: BraTS23 BraTS-Africa Segmentation
rank: 3rd
year: 2023
run_args:
docker_image: brainles/brats23_africa_blackbean:latest
input_name_schema: "BraTS-SSA-{id:05d}-000"
requires_root: true
parameters_file: true
cpu_compatible: true

12 changes: 9 additions & 3 deletions brats/algorithms/meningioma.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ algorithms:
meta:
authors: Andriy Myronenko, et al.
paper: N/A
challenge: BraTS23 Meningioma Segmentation (1st place)
challenge: BraTS23 Meningioma Segmentation
rank: 1st
year: 2023
run_args:
docker_image: brainles/brats23_meningioma_nvauto:latest
input_name_schema: "BraTS-MEN-{id:05d}-000"
Expand All @@ -15,7 +17,9 @@ algorithms:
meta:
authors: Ziyan Huang
paper: N/A
challenge: BraTS23 Meningioma Segmentation (2nd place)
challenge: BraTS23 Meningioma Segmentation
rank: 2nd
year: 2023
run_args:
docker_image: brainles/brats23_meningioma_blackbean:latest
input_name_schema: "BraTS-MEN-{id:05d}-000"
Expand All @@ -28,7 +32,9 @@ algorithms:
meta:
authors: Zhifan Jiang et al.
paper: N/A
challenge: BraTS23 Meningioma Segmentation (3rd place)
challenge: BraTS23 Meningioma Segmentation
rank: 3rd
year: 2023
run_args:
docker_image: brainles/brats23_meningioma_cnmc_pmi2023:latest
input_name_schema: "BraTS-MEN-{id:05d}-000"
Expand Down
Loading