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 #39

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
86 changes: 55 additions & 31 deletions tests/test_hsf.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,22 @@ def config(models_path):
"execution_providers": [
[
"CUDAExecutionProvider",
{"device_id": 0, "gpu_mem_limit": 2147483648},
{
"device_id": 0,
"gpu_mem_limit": 2147483648
},
],
"CPUExecutionProvider",
],
"batch_size": 1,
"batch_size":
1,
},
},
"roiloc": {"roi": "hippocampus", "contrast": "t2", "margin": [2, 0, 2]},
"roiloc": {
"roi": "hippocampus",
"contrast": "t2",
"margin": [2, 0, 2]
},
"augmentation": {
"flip": {
"axes": ["LR"],
Expand All @@ -89,18 +97,24 @@ def config(models_path):
"multispectrality": {
"pattern": None,
"same_space": True,
"registration": {"type_of_transform": "AffineFast"},
"registration": {
"type_of_transform": "AffineFast"
},
},
"segmentation": {
"ca_mode": "1/2/3",
"models_path": str(models_path),
"models": {
"model.onnx": {
"url": "https://zenodo.org/record/6457484/files/arunet_3.0.0_single.onnx?download=1",
"url":
"https://zenodo.org/record/6457484/files/arunet_3.0.0_single.onnx?download=1",
"xxh3_64": "71edec9011f7f304",
}
},
"segmentation": {"test_time_augmentation": True, "test_time_num_aug": 5},
"segmentation": {
"test_time_augmentation": True,
"test_time_num_aug": 5
},
},
}

Expand All @@ -112,9 +126,9 @@ def deepsparse_inference_engines(models_path):
"""Tests that models can be loaded using DeepSparse"""
settings = DictConfig({"num_cores": 0, "batch_size": 2})

engines = hsf.engines.get_inference_engines(
models_path, engine_name="deepsparse", engine_settings=settings
)
engines = hsf.engines.get_inference_engines(models_path,
engine_name="deepsparse",
engine_settings=settings)

return list(engines)

Expand Down Expand Up @@ -157,13 +171,16 @@ def test_roiloc(models_path):

mri, mask = hsf.roiloc_wrapper.get_mri(mris[0], mask_pattern="mask.nii.gz")
assert isinstance(mask, ants.ANTsImage)
mri, mask = hsf.roiloc_wrapper.get_mri(mris[0], mask_pattern="no_mask.nii.gz")
mri, mask = hsf.roiloc_wrapper.get_mri(mris[0],
mask_pattern="no_mask.nii.gz")
assert isinstance(mri, ants.ANTsImage)
assert mask is None

_, right, left = hsf.roiloc_wrapper.get_hippocampi(
mri, {"contrast": "t2", "margin": [2, 0, 2], "roi": "hippocampus"}, mask
)
_, right, left = hsf.roiloc_wrapper.get_hippocampi(mri, {
"contrast": "t2",
"margin": [2, 0, 2],
"roi": "hippocampus"
}, mask)

assert isinstance(right, ants.ANTsImage)
assert isinstance(left, ants.ANTsImage)
Expand Down Expand Up @@ -195,33 +212,40 @@ def test_segment(models_path, config, deepsparse_inference_engines):

def test_multispectrality(models_path):
"""Tests that we can co-locate hippocampi in another contrast."""
config = DictConfig(
{
"files": {"output_dir": str(models_path)},
"multispectrality": {
"pattern": "sub0_tse.nii.gz",
"same_space": False,
"registration": {"type_of_transform": "AffineFast"},
config = DictConfig({
"files": {
"output_dir": str(models_path)
},
"multispectrality": {
"pattern": "sub0_tse.nii.gz",
"same_space": False,
"registration": {
"type_of_transform": "AffineFast"
},
}
)
},
})

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")
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")

registered = hsf.multispectrality.register(
mri, second_contrast, DictConfig({"multispectrality": {"same_space": True}})
)
mri, second_contrast,
DictConfig({"multispectrality": {
"same_space": True
}}))
registered = hsf.multispectrality.register(mri, second_contrast, config)

img = ants.image_read(str(mri), reorient="LPI")
locator, _, _ = hsf.roiloc_wrapper.get_hippocampi(
img, {"contrast": "t2", "margin": [2, 0, 2], "roi": "hippocampus"}, None
)
locator, _, _ = hsf.roiloc_wrapper.get_hippocampi(img, {
"contrast": "t2",
"margin": [2, 0, 2],
"roi": "hippocampus"
}, None)

_, _ = hsf.multispectrality.get_additional_hippocampi(
mri, registered, locator, config
)
mri, registered, locator, config)


def test_uncertainty():
Expand Down