Skip to content
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
3 changes: 2 additions & 1 deletion monai/apps/detection/utils/anchor_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,8 @@ def grid_anchors(self, grid_sizes: List[List[int]], strides: List[List[Tensor]])
"""
anchors = []
cell_anchors = self.cell_anchors
assert cell_anchors is not None
if cell_anchors is None:
raise AssertionError

if not (len(grid_sizes) == len(strides) == len(cell_anchors)):
raise ValueError(
Expand Down
3 changes: 2 additions & 1 deletion monai/networks/blocks/feature_pyramid_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,8 @@ def __init__(
nn.init.constant_(m.bias, 0.0) # type: ignore

if extra_blocks is not None:
assert isinstance(extra_blocks, ExtraFPNBlock)
if not isinstance(extra_blocks, ExtraFPNBlock):
raise AssertionError
self.extra_blocks = extra_blocks

def get_result_from_inner_blocks(self, x: Tensor, idx: int) -> Tensor:
Expand Down
10 changes: 4 additions & 6 deletions tests/test_anchor_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,21 @@

_, has_torchvision = optional_import("torchvision")

TEST_CASES_2D = []
TEST_CASES_2D.append(
TEST_CASES_2D = [
[
{"sizes": ((10, 12, 14, 16), (20, 24, 28, 32)), "aspect_ratios": ((1.0, 0.5, 2.0), (1.0, 0.5, 2.0))},
(5, 3, 128, 128),
((5, 7, 64, 32), (5, 7, 32, 16)),
]
)
]

TEST_CASES_SHAPE_3D = []
TEST_CASES_SHAPE_3D.append(
TEST_CASES_SHAPE_3D = [
[
{"feature_map_scales": (1, 2), "base_anchor_shapes": ((4, 3, 6), (8, 2, 4))},
(5, 3, 128, 128, 128),
((5, 7, 64, 32, 32), (5, 7, 32, 16, 16)),
]
)
]


@SkipIfBeforePyTorchVersion((1, 11))
Expand Down
16 changes: 6 additions & 10 deletions tests/test_fpn_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,22 @@

_, has_torchvision = optional_import("torchvision")

TEST_CASES = []
TEST_CASES.append(
TEST_CASES = [
[
{"spatial_dims": 3, "in_channels_list": [32, 64], "out_channels": 6},
((7, 32, 16, 32, 64), (7, 64, 8, 16, 32)),
((7, 6, 16, 32, 64), (7, 6, 8, 16, 32)),
]
)
TEST_CASES.append(
],
[
{"spatial_dims": 2, "in_channels_list": [32, 64], "out_channels": 6},
((7, 32, 16, 32), (7, 64, 8, 16)),
((7, 6, 16, 32), (7, 6, 8, 16)),
]
)
],
]

TEST_CASES2 = []
TEST_CASES2.append(
TEST_CASES2 = [
[{"spatial_dims": 3, "returned_layers": [1]}, (7, 3, 32, 64, 32), ((7, 256, 16, 32, 16), (7, 256, 8, 16, 8))]
)
]


class TestFPNBlock(unittest.TestCase):
Expand Down
5 changes: 2 additions & 3 deletions tests/test_generate_pos_neg_label_crop_centers.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
from monai.utils.misc import set_determinism
from tests.utils import TEST_NDARRAYS, assert_allclose

TESTS = []
TESTS.append(
TESTS = [
[
{
"spatial_size": [2, 2, 2],
Expand All @@ -33,7 +32,7 @@
2,
3,
]
)
]


class TestGeneratePosNegLabelCropCenters(unittest.TestCase):
Expand Down
9 changes: 4 additions & 5 deletions tests/test_hardnegsampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,16 @@
from monai.apps.detection.utils.hard_negative_sampler import HardNegativeSampler
from tests.utils import assert_allclose

TEST_CASE = []
TEST_CASE.append([[], [], [], [torch.tensor([]), torch.tensor([])], [torch.tensor([]), torch.tensor([])]])
TEST_CASE.append(
TEST_CASE = [
[[], [], [], [torch.tensor([]), torch.tensor([])], [torch.tensor([]), torch.tensor([])]],
[
[0, 1],
[1, 0, 2, 3],
[0.1, 0.9, 0.4, 0.3, 0.3, 0.5],
[torch.tensor([0, 1]), torch.tensor([1, 0, 1, 1])],
[torch.tensor([1, 0]), torch.tensor([0, 1, 0, 0])],
]
)
],
]

select_sample_size_per_image = 6
positive_fraction = 0.5
Expand Down
7 changes: 4 additions & 3 deletions tests/test_optim_novograd.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ def build_test_cases(data):
{"params": [bias], "lr": 1e-2, "amsgrad": True, "grad_averaging": True, "weight_decay": 0.1},
]

test_cases = []
test_cases.append([test_case_same_param, default_params, weight, bias, input])
test_cases.append([test_case_diff_param, default_params, weight, bias, input])
test_cases = [
[test_case_same_param, default_params, weight, bias, input],
[test_case_diff_param, default_params, weight, bias, input],
]
return test_cases


Expand Down
23 changes: 7 additions & 16 deletions tests/test_rand_crop_by_pos_neg_label.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
from monai.transforms import RandCropByPosNegLabel
from tests.utils import TEST_NDARRAYS

TESTS = []
TESTS.append(
TESTS = [
[
{
"label": np.random.randint(0, 2, size=[3, 3, 3, 3]),
Expand All @@ -32,9 +31,7 @@
},
{"img": np.random.randint(0, 2, size=[3, 3, 3, 3])},
(3, 2, 2, 3),
]
)
TESTS.append(
],
[
{
"label": np.random.randint(0, 2, size=[3, 3, 3, 3]),
Expand All @@ -47,9 +44,7 @@
},
{"img": np.random.randint(0, 2, size=[3, 3, 3, 3])},
(3, 2, 2, 2),
]
)
TESTS.append(
],
[
{
"label": None,
Expand All @@ -66,9 +61,7 @@
"image": np.random.randint(0, 2, size=[3, 3, 3, 3]),
},
(3, 2, 2, 2),
]
)
TESTS.append(
],
[
{
"label": np.random.randint(0, 2, size=[3, 3, 3, 3]),
Expand All @@ -81,9 +74,7 @@
},
{"img": np.random.randint(0, 2, size=[3, 3, 3, 3])},
(3, 3, 3, 2),
]
)
TESTS.append(
],
[
{
"label": np.random.randint(0, 2, size=[3, 3, 3, 3]),
Expand All @@ -96,8 +87,8 @@
},
{"img": np.random.randint(0, 2, size=[3, 3, 3, 3])},
(3, 3, 3, 3),
]
)
],
]


class TestRandCropByPosNegLabel(unittest.TestCase):
Expand Down
6 changes: 2 additions & 4 deletions tests/test_to_tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,11 @@

im = [[1, 2], [3, 4]]

TESTS = []
TESTS.append((im, (2, 2)))
TESTS = [(im, (2, 2))]
for p in TEST_NDARRAYS:
TESTS.append((p(im), (2, 2)))

TESTS_SINGLE = []
TESTS_SINGLE.append([5])
TESTS_SINGLE = [[5]]
for p in TEST_NDARRAYS:
TESTS_SINGLE.append([p(5)])

Expand Down
2 changes: 1 addition & 1 deletion tests/test_upsample_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@
test_case = [
{"dimensions": 3, "in_channels": 3, "out_channels": 5, "mode": t, "scale_factor": s, "align_corners": True},
(16, 3, 4, 5, 6),
expected_shape,
]
test_case.append(expected_shape)
TEST_CASES_EQ.append(test_case)


Expand Down