From 540b33f234992fed73ad55b7e185fe55282f2559 Mon Sep 17 00:00:00 2001 From: "deepsource-autofix[bot]" <62050782+deepsource-autofix[bot]@users.noreply.github.com> Date: Fri, 29 Mar 2024 12:32:58 +0000 Subject: [PATCH 1/2] refactor: remove assert statement from non-test files Usage of `assert` statement in application logic is discouraged. `assert` is removed with compiling to optimized byte code. Consider raising an exception instead. Ideally, `assert` statement should be used only in tests. --- hsf/factory.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/hsf/factory.py b/hsf/factory.py index 737436f..5a2468f 100644 --- a/hsf/factory.py +++ b/hsf/factory.py @@ -189,9 +189,10 @@ def main(cfg: DictConfig) -> None: bs = cfg.hardware.engine_settings.batch_size multispectral = 2 if cfg.multispectrality.pattern else 1 - assert multispectral * ( + if multispectral * ( tta + 1 - ) % bs == 0, "test_time_num_aug+1 must be a multiple of batch_size for deepsparse" + ) % bs != 0: + raise AssertionError("test_time_num_aug+1 must be a multiple of batch_size for deepsparse") mris = load_from_config(cfg.files.path, cfg.files.pattern) _n = len(mris) From 5ac4253d2b065edecff72eef16aecde53c92ea4c Mon Sep 17 00:00:00 2001 From: "deepsource-autofix[bot]" <62050782+deepsource-autofix[bot]@users.noreply.github.com> Date: Fri, 29 Mar 2024 12:33:08 +0000 Subject: [PATCH 2/2] style: format code with isort and Yapf This commit fixes the style issues introduced in 540b33f according to the output from isort and Yapf. Details: https://github.com/clementpoiret/HSF/pull/32 --- hsf/factory.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/hsf/factory.py b/hsf/factory.py index 5a2468f..7d33fc8 100644 --- a/hsf/factory.py +++ b/hsf/factory.py @@ -28,7 +28,6 @@ log = logging.getLogger(__name__) - def get_lr_hippocampi(mri: PosixPath, cfg: DictConfig) -> tuple: """ Get left and right hippocampi from a given MRI. @@ -63,8 +62,8 @@ def get_lr_hippocampi(mri: PosixPath, cfg: DictConfig) -> tuple: original_mri_path=mri) -def predict(mri: PosixPath, second_mri: Optional[PosixPath], engines: Generator, - cfg: DictConfig) -> tuple: +def predict(mri: PosixPath, second_mri: Optional[PosixPath], + engines: Generator, cfg: DictConfig) -> tuple: """ Predict the hippocampal segmentation for a given MRI. @@ -156,7 +155,8 @@ def filter_mris(mris: List[PosixPath], overwrite: bool) -> List[PosixPath]: def _get_segmentations(mri: PosixPath) -> List[PosixPath]: extensions = "".join(mri.suffixes) stem = mri.name.replace(extensions, "") - segmentations = list(mri.parent.glob(f"{stem}*_hippocampus_seg.nii.gz")) + segmentations = list( + mri.parent.glob(f"{stem}*_hippocampus_seg.nii.gz")) if len(segmentations) > 2: log.warning( @@ -189,10 +189,10 @@ def main(cfg: DictConfig) -> None: bs = cfg.hardware.engine_settings.batch_size multispectral = 2 if cfg.multispectrality.pattern else 1 - if multispectral * ( - tta + 1 - ) % bs != 0: - raise AssertionError("test_time_num_aug+1 must be a multiple of batch_size for deepsparse") + if multispectral * (tta + 1) % bs != 0: + raise AssertionError( + "test_time_num_aug+1 must be a multiple of batch_size for deepsparse" + ) mris = load_from_config(cfg.files.path, cfg.files.pattern) _n = len(mris) @@ -230,7 +230,8 @@ def main(cfg: DictConfig) -> None: else: additional_hippocampi = [None, None] - for j, hippocampus in enumerate(zip(hippocampi, additional_hippocampi)): + for j, hippocampus in enumerate(zip(hippocampi, + additional_hippocampi)): engines = get_inference_engines( cfg.segmentation.models_path, engine_name=cfg.hardware.engine,