-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from BrainLesion/feature/inferrer-class
Feature/inferrer class
- Loading branch information
Showing
33 changed files
with
1,455 additions
and
768 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions | ||
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python | ||
|
||
name: tests | ||
|
||
on: | ||
push: | ||
branches: ["main"] | ||
pull_request: | ||
branches: ["main"] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
python-version: ["3.10"] #TODO add 3.11 support (for 3.12 torch is not available yet) | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Set up Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v3 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
python -m pip install flake8 pytest | ||
pip install -e . | ||
- name: Lint with flake8 | ||
run: | | ||
# stop the build if there are Python syntax errors or undefined names | ||
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics | ||
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide | ||
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics | ||
- name: Test with pytest | ||
run: | | ||
pytest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
from enum import Enum | ||
|
||
|
||
class InferenceMode(str, Enum): | ||
"""Enum representing different modes of inference based on available image inputs | ||
Enum Values: | ||
T1_T1C_T2_FLA (str): All four modalities are available. | ||
T1_T1C_FLA (str): T1, T1C, and FLAIR are available. | ||
T1_T1C (str): T1 and T1C are available. | ||
T1C_FLA (str): T1C and FLAIR are available. | ||
T1C_O (str): T1C is available. | ||
FLA_O (str): FLAIR is available. | ||
T1_O (str): T1 is available. | ||
""" | ||
|
||
T1_T1C_T2_FLA = "t1-t1c-t2-fla" | ||
T1_T1C_FLA = "t1-t1c-fla" | ||
T1_T1C = "t1-t1c" | ||
T1C_FLA = "t1c-fla" | ||
T1C_O = "t1c-o" | ||
FLA_O = "fla-o" | ||
T1_O = "t1-o" | ||
|
||
|
||
class ModelSelection(str, Enum): | ||
"""Enum representing different strategies for model selection. | ||
Enum Values: | ||
BEST (str): Select the best performing model. | ||
LAST (str): Select the last model. | ||
VANILLA (str): Select the vanilla model. | ||
""" | ||
|
||
BEST = "best" | ||
LAST = "last" | ||
VANILLA = "vanilla" | ||
|
||
|
||
class DataMode(str, Enum): | ||
"""Enum representing different modes for handling input and output data. | ||
Enum Values: | ||
NIFTI_FILE (str): Input data is provided as NIFTI file paths/ output is writte to NIFTI files. | ||
NUMPY (str): Input data is provided as NumPy arrays/ output is returned as NumPy arrays. | ||
""" | ||
|
||
NIFTI_FILE = "NIFTI_FILEPATH" | ||
NUMPY = "NP_NDARRAY" | ||
|
||
|
||
class Output(str, Enum): | ||
"""Enum representing different types of output. | ||
Enum Values: | ||
SEGMENTATION (str): Segmentation mask. | ||
WHOLE_NETWORK (str): Whole network output. | ||
METASTASIS_NETWORK (str): Metastasis network output. | ||
""" | ||
|
||
SEGMENTATION = "segmentation" | ||
WHOLE_NETWORK = "whole_network" | ||
METASTASIS_NETWORK = "metastasis_network" | ||
|
||
|
||
MODALITIES = ["t1", "t1c", "t2", "fla"] | ||
"""List of modality names in standard order: T1 T1C T2 FLAIR (['t1', 't1c', 't2', 'fla'])""" | ||
|
||
|
||
# booleans indicate presence of files in order: T1 T1C T2 FLAIR | ||
IMGS_TO_MODE_DICT = { | ||
(True, True, True, True): InferenceMode.T1_T1C_T2_FLA, | ||
(True, True, False, True): InferenceMode.T1_T1C_FLA, | ||
(True, True, False, False): InferenceMode.T1_T1C, | ||
(False, True, False, True): InferenceMode.T1C_FLA, | ||
(False, True, False, False): InferenceMode.T1C_O, | ||
(False, False, False, True): InferenceMode.FLA_O, | ||
(True, False, False, False): InferenceMode.T1_O, | ||
} | ||
"""Dictionary mapping tuples of booleans representing presence of the modality in order [t1,t1c,t2,fla] to InferenceMode values.""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import logging | ||
from dataclasses import dataclass | ||
from typing import Tuple | ||
|
||
|
||
from brainles_aurora.inferer.constants import DataMode, ModelSelection | ||
|
||
|
||
@dataclass | ||
class BaseConfig: | ||
"""Base configuration for the Aurora model inferer. | ||
Attributes: | ||
output_mode (DataMode, optional): Output mode for the inference results. Defaults to DataMode.NIFTI_FILE. | ||
log_level (int | str, optional): Logging level. Defaults to logging.INFO. | ||
""" | ||
|
||
output_mode: DataMode = DataMode.NIFTI_FILE | ||
log_level: int | str = logging.INFO | ||
|
||
|
||
@dataclass | ||
class AuroraInfererConfig(BaseConfig): | ||
"""Configuration for the Aurora model inferer. | ||
Attributes: | ||
output_mode (DataMode, optional): Output mode for the inference results. Defaults to DataMode.NIFTI_FILE. | ||
log_level (int | str, optional): Logging level. Defaults to logging.INFO. | ||
tta (bool, optional): Whether to apply test-time augmentations. Defaults to True. | ||
sliding_window_batch_size (int, optional): Batch size for sliding window inference. Defaults to 1. | ||
workers (int, optional): Number of workers for data loading. Defaults to 0. | ||
threshold (float, optional): Threshold for binarizing the model outputs. Defaults to 0.5. | ||
sliding_window_overlap (float, optional): Overlap ratio for sliding window inference. Defaults to 0.5. | ||
crop_size (Tuple[int, int, int], optional): Crop size for sliding window inference. Defaults to (192, 192, 32). | ||
model_selection (ModelSelection, optional): Model selection strategy. Defaults to ModelSelection.BEST. | ||
""" | ||
|
||
tta: bool = True | ||
sliding_window_batch_size: int = 1 | ||
workers: int = 0 | ||
threshold: float = 0.5 | ||
sliding_window_overlap: float = 0.5 | ||
crop_size: Tuple[int, int, int] = (192, 192, 32) | ||
model_selection: ModelSelection = ModelSelection.BEST |
Oops, something went wrong.