Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Signed-off-by: YunLiu <[email protected]>
  • Loading branch information
KumoLiu committed Jan 29, 2024
1 parent 6c9e49e commit cc94076
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 34 deletions.
8 changes: 6 additions & 2 deletions monai/apps/detection/utils/anchor_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,8 +369,12 @@ class AnchorGeneratorWithAnchorShape(AnchorGenerator):
def __init__(
self,
feature_map_scales: Sequence[int] | Sequence[float] = (1, 2, 4, 8),
base_anchor_shapes: Sequence[Sequence[int]]
| Sequence[Sequence[float]] = ((32, 32, 32), (48, 20, 20), (20, 48, 20), (20, 20, 48)),
base_anchor_shapes: Sequence[Sequence[int]] | Sequence[Sequence[float]] = (
(32, 32, 32),
(48, 20, 20),
(20, 48, 20),
(20, 20, 48),
),
indexing: str = "ij",
) -> None:
nn.Module.__init__(self)
Expand Down
6 changes: 2 additions & 4 deletions monai/data/decathlon_datalist.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,11 @@


@overload
def _compute_path(base_dir: PathLike, element: PathLike, check_path: bool = False) -> str:
...
def _compute_path(base_dir: PathLike, element: PathLike, check_path: bool = False) -> str: ...


@overload
def _compute_path(base_dir: PathLike, element: list[PathLike], check_path: bool = False) -> list[str]:
...
def _compute_path(base_dir: PathLike, element: list[PathLike], check_path: bool = False) -> list[str]: ...


def _compute_path(base_dir, element, check_path=False):
Expand Down
4 changes: 1 addition & 3 deletions monai/losses/image_dissimilarity.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,9 +277,7 @@ def parzen_windowing_b_spline(self, img: torch.Tensor, order: int) -> tuple[torc
if order == 0:
weight = weight + (sample_bin_matrix < 0.5) + (sample_bin_matrix == 0.5) * 0.5
elif order == 3:
weight = (
weight + (4 - 6 * sample_bin_matrix**2 + 3 * sample_bin_matrix**3) * (sample_bin_matrix < 1) / 6
)
weight = weight + (4 - 6 * sample_bin_matrix**2 + 3 * sample_bin_matrix**3) * (sample_bin_matrix < 1) / 6
weight = weight + (2 - sample_bin_matrix) ** 3 * (sample_bin_matrix >= 1) * (sample_bin_matrix < 2) / 6
else:
raise ValueError(f"Do not support b-spline {order}-order parzen windowing")
Expand Down
6 changes: 3 additions & 3 deletions monai/transforms/utility/dictionary.py
Original file line number Diff line number Diff line change
Expand Up @@ -1765,9 +1765,9 @@ def __call__(self, data: Mapping[Hashable, NdarrayOrTensor]) -> dict[Hashable, N
LabelToMaskD = LabelToMaskDict = LabelToMaskd
FgBgToIndicesD = FgBgToIndicesDict = FgBgToIndicesd
ClassesToIndicesD = ClassesToIndicesDict = ClassesToIndicesd
ConvertToMultiChannelBasedOnBratsClassesD = (
ConvertToMultiChannelBasedOnBratsClassesDict
) = ConvertToMultiChannelBasedOnBratsClassesd
ConvertToMultiChannelBasedOnBratsClassesD = ConvertToMultiChannelBasedOnBratsClassesDict = (
ConvertToMultiChannelBasedOnBratsClassesd
)
AddExtremePointsChannelD = AddExtremePointsChannelDict = AddExtremePointsChanneld
TorchVisionD = TorchVisionDict = TorchVisiond
RandTorchVisionD = RandTorchVisionDict = RandTorchVisiond
Expand Down
9 changes: 3 additions & 6 deletions monai/utils/dist.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,15 @@ def get_dist_device():


@overload
def evenly_divisible_all_gather(data: torch.Tensor, concat: Literal[True]) -> torch.Tensor:
...
def evenly_divisible_all_gather(data: torch.Tensor, concat: Literal[True]) -> torch.Tensor: ...


@overload
def evenly_divisible_all_gather(data: torch.Tensor, concat: Literal[False]) -> list[torch.Tensor]:
...
def evenly_divisible_all_gather(data: torch.Tensor, concat: Literal[False]) -> list[torch.Tensor]: ...


@overload
def evenly_divisible_all_gather(data: torch.Tensor, concat: bool) -> torch.Tensor | list[torch.Tensor]:
...
def evenly_divisible_all_gather(data: torch.Tensor, concat: bool) -> torch.Tensor | list[torch.Tensor]: ...


def evenly_divisible_all_gather(data: torch.Tensor, concat: bool = True) -> torch.Tensor | list[torch.Tensor]:
Expand Down
6 changes: 2 additions & 4 deletions monai/utils/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,11 @@ def star_zip_with(op, *vals):


@overload
def first(iterable: Iterable[T], default: T) -> T:
...
def first(iterable: Iterable[T], default: T) -> T: ...


@overload
def first(iterable: Iterable[T]) -> T | None:
...
def first(iterable: Iterable[T]) -> T | None: ...


def first(iterable: Iterable[T], default: T | None = None) -> T | None:
Expand Down
2 changes: 2 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ max_line_length = 120
# B907 https://github.com/Project-MONAI/MONAI/issues/5868
# B908 https://github.com/Project-MONAI/MONAI/issues/6503
# B036 https://github.com/Project-MONAI/MONAI/issues/7396
# E704 https://github.com/Project-MONAI/MONAI/issues/7421
ignore =
E203
E501
Expand All @@ -188,6 +189,7 @@ ignore =
B907
B908
B036
E704
per_file_ignores = __init__.py: F401, __main__.py: F401
exclude = *.pyi,.git,.eggs,monai/_version.py,versioneer.py,venv,.venv,_version.py

Expand Down
20 changes: 11 additions & 9 deletions tests/test_hilbert_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,15 +180,17 @@ def test_value(self, arguments, image, expected_data, atol):
@SkipIfNoModule("torch.fft")
class TestHilbertTransformGPU(unittest.TestCase):
@parameterized.expand(
[]
if not torch.cuda.is_available()
else [
TEST_CASE_1D_SINE_GPU,
TEST_CASE_2D_SINE_GPU,
TEST_CASE_3D_SINE_GPU,
TEST_CASE_1D_2CH_SINE_GPU,
TEST_CASE_2D_2CH_SINE_GPU,
],
(
[]
if not torch.cuda.is_available()
else [
TEST_CASE_1D_SINE_GPU,
TEST_CASE_2D_SINE_GPU,
TEST_CASE_3D_SINE_GPU,
TEST_CASE_1D_2CH_SINE_GPU,
TEST_CASE_2D_2CH_SINE_GPU,
]
),
skip_on_empty=True,
)
def test_value(self, arguments, image, expected_data, atol):
Expand Down
8 changes: 5 additions & 3 deletions tests/test_spacing.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,11 @@
torch.ones((1, 2, 1, 2)), # data
torch.tensor([[2, 1, 0, 4], [-1, -3, 0, 5], [0, 0, 2.0, 5], [0, 0, 0, 1]]),
{},
torch.tensor([[[[0.75, 0.75]], [[0.75, 0.75]], [[0.75, 0.75]]]])
if USE_COMPILED
else torch.tensor([[[[0.95527864, 0.95527864]], [[1.0, 1.0]], [[1.0, 1.0]]]]),
(
torch.tensor([[[[0.75, 0.75]], [[0.75, 0.75]], [[0.75, 0.75]]]])
if USE_COMPILED
else torch.tensor([[[[0.95527864, 0.95527864]], [[1.0, 1.0]], [[1.0, 1.0]]]])
),
*device,
]
)
Expand Down

0 comments on commit cc94076

Please sign in to comment.