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

style: format code with isort and Yapf #31

Merged
merged 1 commit into from
Mar 29, 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
4 changes: 2 additions & 2 deletions hsf/augmentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ def get_augmentation_pipeline(augmentation_cfg: DictConfig) -> tio.Compose:
flip = tio.RandomFlip(**augmentation_cfg.flip)
resample = tio.OneOf({
tio.RandomAffine(**augmentation_cfg.affine):
augmentation_cfg.affine_probability,
augmentation_cfg.affine_probability,
tio.RandomElasticDeformation(**augmentation_cfg.elastic):
augmentation_cfg.elastic_probability
augmentation_cfg.elastic_probability
})

return tio.Compose((flip, resample))
Expand Down
11 changes: 6 additions & 5 deletions hsf/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -229,7 +229,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,
Expand Down
3 changes: 1 addition & 2 deletions hsf/multispectrality.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@ def register(mri: PosixPath,
transformlist=transformation["fwdtransforms"])

extensions = "".join(second_contrast.suffixes)
fname = second_contrast.name.replace(extensions,
"") + "_registered.nii.gz"
fname = second_contrast.name.replace(extensions, "") + "_registered.nii.gz"
output_dir = mri.parent / cfg.files.output_dir
output_dir.mkdir(parents=True, exist_ok=True)

Expand Down
3 changes: 2 additions & 1 deletion hsf/roiloc_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ def get_mri(mri: PosixPath, mask_pattern: Optional[str] = None) -> tuple:
else:
mask = None
log.warning(
"Couldn't find brain extraction mask for the provided pattern.")
"Couldn't find brain extraction mask for the provided pattern."
)
else:
mask = None

Expand Down
7 changes: 3 additions & 4 deletions hsf/segment.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,13 @@ def to_ca_mode(logits: torch.Tensor, ca_mode: str = "1/2/3") -> torch.Tensor:
_pre = logits[:, :2, :, :, :]
_in = logits[:,
2:3, :, :, :] + logits[:,
3:4, :, :, :] + logits[:,
4:5, :, :, :]
3:4, :, :, :] + logits[:, 4:
5, :, :, :]
_post = logits[:, 5:, :, :, :]

return torch.cat([_pre, _in, _post], dim=1)
raise ValueError(
f"Unknown `ca_mode` ({ca_mode}). `ca_mode` must be 1/2/3, 1/23 or 123"
)
f"Unknown `ca_mode` ({ca_mode}). `ca_mode` must be 1/2/3, 1/23 or 123")


def predict(mris: list,
Expand Down
11 changes: 6 additions & 5 deletions tests/test_hsf.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ def config(models_path):
"gpu_mem_limit": 2147483648
}
], "CPUExecutionProvider"],
"batch_size": 1
"batch_size":
1
}
},
"roiloc": {
Expand Down Expand Up @@ -102,9 +103,8 @@ def config(models_path):
"models": {
"model.onnx": {
"url":
"https://zenodo.org/record/6457484/files/arunet_3.0.0_single.onnx?download=1",
"xxh3_64":
"71edec9011f7f304"
"https://zenodo.org/record/6457484/files/arunet_3.0.0_single.onnx?download=1",
"xxh3_64": "71edec9011f7f304"
}
},
"segmentation": {
Expand Down Expand Up @@ -220,7 +220,8 @@ def test_multispectrality(models_path):
}
})

mri = hsf.roiloc_wrapper.load_from_config(models_path, "sub0_tse.nii.gz")[0]
mri = hsf.roiloc_wrapper.load_from_config(models_path,
"sub0_tse.nii.gz")[0]
second_contrast = hsf.multispectrality.get_second_contrast(
mri, "sub0_tse.nii.gz")

Expand Down
Loading