diff --git a/monai/transforms/utils.py b/monai/transforms/utils.py index 2d4239426e..c040741831 100644 --- a/monai/transforms/utils.py +++ b/monai/transforms/utils.py @@ -297,17 +297,17 @@ def create_rotate(spatial_dims, radians): if len(radians) >= 1: sin_, cos_ = np.sin(radians[0]), np.cos(radians[0]) affine = np.array( - [[1.0, 0.0, 0.0, 0.0], [0.0, cos_, -sin_, 0.0], [0.0, sin_, cos_, 0.0], [0.0, 0.0, 0.0, 1.0],] + [[1.0, 0.0, 0.0, 0.0], [0.0, cos_, -sin_, 0.0], [0.0, sin_, cos_, 0.0], [0.0, 0.0, 0.0, 1.0]] ) if len(radians) >= 2: sin_, cos_ = np.sin(radians[1]), np.cos(radians[1]) affine = affine @ np.array( - [[cos_, 0.0, sin_, 0.0], [0.0, 1.0, 0.0, 0.0], [-sin_, 0.0, cos_, 0.0], [0.0, 0.0, 0.0, 1.0],] + [[cos_, 0.0, sin_, 0.0], [0.0, 1.0, 0.0, 0.0], [-sin_, 0.0, cos_, 0.0], [0.0, 0.0, 0.0, 1.0]] ) if len(radians) >= 3: sin_, cos_ = np.sin(radians[2]), np.cos(radians[2]) affine = affine @ np.array( - [[cos_, -sin_, 0.0, 0.0], [sin_, cos_, 0.0, 0.0], [0.0, 0.0, 1.0, 0.0], [0.0, 0.0, 0.0, 1.0],] + [[cos_, -sin_, 0.0, 0.0], [sin_, cos_, 0.0, 0.0], [0.0, 0.0, 1.0, 0.0], [0.0, 0.0, 0.0, 1.0]] ) return affine @@ -325,7 +325,7 @@ def create_shear(spatial_dims, coefs): if spatial_dims == 2: while len(coefs) < 2: coefs.append(0.0) - return np.array([[1, coefs[0], 0.0], [coefs[1], 1.0, 0.0], [0.0, 0.0, 1.0],]) + return np.array([[1, coefs[0], 0.0], [coefs[1], 1.0, 0.0], [0.0, 0.0, 1.0]]) if spatial_dims == 3: while len(coefs) < 6: coefs.append(0.0) diff --git a/tests/test_crop_foreground.py b/tests/test_crop_foreground.py index 416331c54c..5b759dbc0e 100644 --- a/tests/test_crop_foreground.py +++ b/tests/test_crop_foreground.py @@ -18,7 +18,7 @@ TEST_CASE_1 = [ {"select_fn": lambda x: x > 0, "channel_indexes": None, "margin": 0}, np.array([[[0, 0, 0, 0, 0], [0, 1, 2, 1, 0], [0, 2, 3, 2, 0], [0, 1, 2, 1, 0], [0, 0, 0, 0, 0]]]), - np.array([[[1, 2, 1], [2, 3, 2], [1, 2, 1],]]), + np.array([[[1, 2, 1], [2, 3, 2], [1, 2, 1]]]), ] TEST_CASE_2 = [ @@ -30,7 +30,7 @@ TEST_CASE_3 = [ {"select_fn": lambda x: x > 0, "channel_indexes": 0, "margin": 0}, np.array([[[0, 0, 0, 0, 0], [0, 1, 2, 1, 0], [0, 2, 3, 2, 0], [0, 1, 2, 1, 0], [0, 0, 0, 0, 0]]]), - np.array([[[1, 2, 1], [2, 3, 2], [1, 2, 1],]]), + np.array([[[1, 2, 1], [2, 3, 2], [1, 2, 1]]]), ] TEST_CASE_4 = [ diff --git a/tests/test_crop_foregroundd.py b/tests/test_crop_foregroundd.py index faacb2b06a..9d52ec462e 100644 --- a/tests/test_crop_foregroundd.py +++ b/tests/test_crop_foregroundd.py @@ -27,7 +27,7 @@ "img": np.array([[[1, 0, 2, 0, 1], [0, 1, 2, 1, 0], [2, 2, 3, 2, 2], [0, 1, 2, 1, 0], [1, 0, 2, 0, 1]]]), "label": np.array([[[0, 0, 0, 0, 0], [0, 1, 0, 1, 0], [0, 0, 1, 0, 0], [0, 1, 0, 1, 0], [0, 0, 0, 0, 0]]]), }, - np.array([[[1, 2, 1], [2, 3, 2], [1, 2, 1],]]), + np.array([[[1, 2, 1], [2, 3, 2], [1, 2, 1]]]), ] TEST_CASE_2 = [ @@ -39,7 +39,7 @@ TEST_CASE_3 = [ {"keys": ["img"], "source_key": "img", "select_fn": lambda x: x > 0, "channel_indexes": 0, "margin": 0}, {"img": np.array([[[0, 0, 0, 0, 0], [0, 1, 2, 1, 0], [0, 2, 3, 2, 0], [0, 1, 2, 1, 0], [0, 0, 0, 0, 0]]])}, - np.array([[[1, 2, 1], [2, 3, 2], [1, 2, 1],]]), + np.array([[[1, 2, 1], [2, 3, 2], [1, 2, 1]]]), ] TEST_CASE_4 = [ diff --git a/tests/test_dice_loss.py b/tests/test_dice_loss.py index ccc800e619..0733db1bf0 100644 --- a/tests/test_dice_loss.py +++ b/tests/test_dice_loss.py @@ -17,7 +17,7 @@ from monai.losses import DiceLoss TEST_CASE_1 = [ # shape: (1, 1, 2, 2), (1, 1, 2, 2) - {"include_background": True, "do_sigmoid": True,}, + {"include_background": True, "do_sigmoid": True}, { "pred": torch.tensor([[[[1.0, -1.0], [-1.0, 1.0]]]]), "ground": torch.tensor([[[[1.0, 0.0], [1.0, 1.0]]]]), @@ -27,7 +27,7 @@ ] TEST_CASE_2 = [ # shape: (2, 1, 2, 2), (2, 1, 2, 2) - {"include_background": True, "do_sigmoid": True,}, + {"include_background": True, "do_sigmoid": True}, { "pred": torch.tensor([[[[1.0, -1.0], [-1.0, 1.0]]], [[[1.0, -1.0], [-1.0, 1.0]]]]), "ground": torch.tensor([[[[1.0, 1.0], [1.0, 1.0]]], [[[1.0, 0.0], [1.0, 0.0]]]]), @@ -37,7 +37,7 @@ ] TEST_CASE_3 = [ # shape: (2, 2, 3), (2, 1, 3) - {"include_background": False, "to_onehot_y": True,}, + {"include_background": False, "to_onehot_y": True}, { "pred": torch.tensor([[[1.0, 1.0, 0.0], [0.0, 0.0, 1.0]], [[1.0, 0.0, 1.0], [0.0, 1.0, 0.0]]]), "ground": torch.tensor([[[0.0, 0.0, 1.0]], [[0.0, 1.0, 0.0]]]), @@ -47,7 +47,7 @@ ] TEST_CASE_4 = [ # shape: (2, 2, 3), (2, 1, 3) - {"include_background": True, "to_onehot_y": True, "do_sigmoid": True,}, + {"include_background": True, "to_onehot_y": True, "do_sigmoid": True}, { "pred": torch.tensor([[[-1.0, 0.0, 1.0], [1.0, 0.0, -1.0]], [[0.0, 0.0, 0.0], [0.0, 0.0, 0.0]]]), "ground": torch.tensor([[[1.0, 0.0, 0.0]], [[1.0, 1.0, 0.0]]]), @@ -57,7 +57,7 @@ ] TEST_CASE_5 = [ # shape: (2, 2, 3), (2, 1, 3) - {"include_background": True, "to_onehot_y": True, "do_softmax": True,}, + {"include_background": True, "to_onehot_y": True, "do_softmax": True}, { "pred": torch.tensor([[[-1.0, 0.0, 1.0], [1.0, 0.0, -1.0]], [[0.0, 0.0, 0.0], [0.0, 0.0, 0.0]]]), "ground": torch.tensor([[[1.0, 0.0, 0.0]], [[1.0, 1.0, 0.0]]]), @@ -67,7 +67,7 @@ ] TEST_CASE_6 = [ # shape: (1, 1, 2, 2), (1, 1, 2, 2) - {"include_background": True, "do_sigmoid": True,}, + {"include_background": True, "do_sigmoid": True}, { "pred": torch.tensor([[[[1.0, -1.0], [-1.0, 1.0]]]]), "ground": torch.tensor([[[[1.0, 0.0], [1.0, 1.0]]]]), @@ -77,7 +77,7 @@ ] TEST_CASE_7 = [ # shape: (1, 1, 2, 2), (1, 1, 2, 2) - {"include_background": True, "do_sigmoid": True, "squared_pred": True,}, + {"include_background": True, "do_sigmoid": True, "squared_pred": True}, { "pred": torch.tensor([[[[1.0, -1.0], [-1.0, 1.0]]]]), "ground": torch.tensor([[[[1.0, 0.0], [1.0, 1.0]]]]), @@ -87,7 +87,7 @@ ] TEST_CASE_8 = [ # shape: (1, 1, 2, 2), (1, 1, 2, 2) - {"include_background": True, "do_sigmoid": True, "jaccard": True,}, + {"include_background": True, "do_sigmoid": True, "jaccard": True}, { "pred": torch.tensor([[[[1.0, -1.0], [-1.0, 1.0]]]]), "ground": torch.tensor([[[[1.0, 0.0], [1.0, 1.0]]]]), diff --git a/tests/test_generalized_dice_loss.py b/tests/test_generalized_dice_loss.py index 49a3e4c072..ae0b2e295d 100644 --- a/tests/test_generalized_dice_loss.py +++ b/tests/test_generalized_dice_loss.py @@ -17,7 +17,7 @@ from monai.losses import GeneralizedDiceLoss TEST_CASE_0 = [ # shape: (1, 1, 2, 2), (1, 1, 2, 2) - {"include_background": True, "do_sigmoid": True,}, + {"include_background": True, "do_sigmoid": True}, { "pred": torch.tensor([[[[1.0, -1.0], [-1.0, 1.0]]]]), "ground": torch.tensor([[[[1.0, 0.0], [1.0, 1.0]]]]), @@ -27,7 +27,7 @@ ] TEST_CASE_1 = [ # shape: (2, 1, 2, 2), (2, 1, 2, 2) - {"include_background": True, "do_sigmoid": True,}, + {"include_background": True, "do_sigmoid": True}, { "pred": torch.tensor([[[[1.0, -1.0], [-1.0, 1.0]]], [[[1.0, -1.0], [-1.0, 1.0]]]]), "ground": torch.tensor([[[[1.0, 1.0], [1.0, 1.0]]], [[[1.0, 0.0], [1.0, 0.0]]]]), @@ -37,7 +37,7 @@ ] TEST_CASE_2 = [ # shape: (2, 2, 3), (2, 1, 3) - {"include_background": False, "to_onehot_y": True,}, + {"include_background": False, "to_onehot_y": True}, { "pred": torch.tensor([[[1.0, 1.0, 0.0], [0.0, 0.0, 1.0]], [[1.0, 0.0, 1.0], [0.0, 1.0, 0.0]]]), "ground": torch.tensor([[[0.0, 0.0, 1.0]], [[0.0, 1.0, 0.0]]]), @@ -47,7 +47,7 @@ ] TEST_CASE_3 = [ # shape: (2, 2, 3), (2, 1, 3) - {"include_background": True, "to_onehot_y": True, "do_sigmoid": True,}, + {"include_background": True, "to_onehot_y": True, "do_sigmoid": True}, { "pred": torch.tensor([[[-1.0, 0.0, 1.0], [1.0, 0.0, -1.0]], [[0.0, 0.0, 0.0], [0.0, 0.0, 0.0]]]), "ground": torch.tensor([[[1.0, 0.0, 0.0]], [[1.0, 1.0, 0.0]]]), @@ -57,7 +57,7 @@ ] TEST_CASE_4 = [ # shape: (2, 2, 3), (2, 1, 3) - {"include_background": True, "to_onehot_y": True, "do_softmax": True,}, + {"include_background": True, "to_onehot_y": True, "do_softmax": True}, { "pred": torch.tensor([[[-1.0, 0.0, 1.0], [1.0, 0.0, -1.0]], [[0.0, 0.0, 0.0], [0.0, 0.0, 0.0]]]), "ground": torch.tensor([[[1.0, 0.0, 0.0]], [[1.0, 1.0, 0.0]]]), @@ -67,7 +67,7 @@ ] TEST_CASE_5 = [ # shape: (2, 2, 3), (2, 1, 3) - {"include_background": False, "to_onehot_y": True,}, + {"include_background": False, "to_onehot_y": True}, { "pred": torch.tensor([[[1.0, 1.0, 0.0], [0.0, 0.0, 1.0]], [[1.0, 0.0, 1.0], [0.0, 1.0, 0.0]]]), "ground": torch.tensor([[[0.0, 0.0, 0.0]], [[0.0, 0.0, 0.0]]]), @@ -77,7 +77,7 @@ ] TEST_CASE_6 = [ # shape: (1, 1, 2, 2), (1, 1, 2, 2) - {"include_background": True, "do_sigmoid": True,}, + {"include_background": True, "do_sigmoid": True}, { "pred": torch.tensor([[[[1.0, -1.0], [-1.0, 1.0]]]]), "ground": torch.tensor([[[[1.0, 0.0], [1.0, 1.0]]]]), diff --git a/tests/test_highresnet.py b/tests/test_highresnet.py index 1be49520f5..a9471bb5ed 100644 --- a/tests/test_highresnet.py +++ b/tests/test_highresnet.py @@ -17,25 +17,25 @@ from monai.networks.nets import HighResNet TEST_CASE_1 = [ # single channel 3D, batch 16 - {"spatial_dims": 3, "in_channels": 1, "out_channels": 3, "norm_type": "instance",}, + {"spatial_dims": 3, "in_channels": 1, "out_channels": 3, "norm_type": "instance"}, torch.randn(16, 1, 32, 24, 48), (16, 3, 32, 24, 48), ] TEST_CASE_2 = [ # 4-channel 3D, batch 1 - {"spatial_dims": 3, "in_channels": 4, "out_channels": 3, "acti_type": "relu6",}, + {"spatial_dims": 3, "in_channels": 4, "out_channels": 3, "acti_type": "relu6"}, torch.randn(1, 4, 17, 64, 48), (1, 3, 17, 64, 48), ] TEST_CASE_3 = [ # 4-channel 2D, batch 7 - {"spatial_dims": 2, "in_channels": 4, "out_channels": 3,}, + {"spatial_dims": 2, "in_channels": 4, "out_channels": 3}, torch.randn(7, 4, 64, 48), (7, 3, 64, 48), ] TEST_CASE_4 = [ # 4-channel 1D, batch 16 - {"spatial_dims": 1, "in_channels": 4, "out_channels": 3, "dropout_prob": 0.1,}, + {"spatial_dims": 1, "in_channels": 4, "out_channels": 3, "dropout_prob": 0.1}, torch.randn(16, 4, 63), (16, 3, 63), ] diff --git a/tests/test_spacing.py b/tests/test_spacing.py index c3886e4137..5749fcbfe6 100644 --- a/tests/test_spacing.py +++ b/tests/test_spacing.py @@ -27,7 +27,7 @@ [ {"pixdim": (1.0, 0.2, 1.5), "diagonal": False}, np.ones((1, 2, 1, 2)), # data - {"affine": np.array([[2, 1, 0, 4], [-1, -3, 0, 5], [0, 0, 2.0, 5], [0, 0, 0, 1]],),}, + {"affine": np.array([[2, 1, 0, 4], [-1, -3, 0, 5], [0, 0, 2.0, 5], [0, 0, 0, 1]])}, np.zeros((1, 3, 1, 2)), ], [ diff --git a/tests/test_squeezedimd.py b/tests/test_squeezedimd.py index a2405ba6dd..f73aef5b11 100644 --- a/tests/test_squeezedimd.py +++ b/tests/test_squeezedimd.py @@ -17,36 +17,36 @@ TEST_CASE_1 = [ {"keys": ["img", "seg"], "dim": None}, - {"img": np.random.rand(1, 2, 1, 3), "seg": np.random.randint(0, 2, size=[1, 2, 1, 3]),}, + {"img": np.random.rand(1, 2, 1, 3), "seg": np.random.randint(0, 2, size=[1, 2, 1, 3])}, (2, 3), ] TEST_CASE_2 = [ {"keys": ["img", "seg"], "dim": 2}, - {"img": np.random.rand(1, 2, 1, 8, 16), "seg": np.random.randint(0, 2, size=[1, 2, 1, 8, 16]),}, + {"img": np.random.rand(1, 2, 1, 8, 16), "seg": np.random.randint(0, 2, size=[1, 2, 1, 8, 16])}, (1, 2, 8, 16), ] TEST_CASE_3 = [ {"keys": ["img", "seg"], "dim": -1}, - {"img": np.random.rand(1, 1, 16, 8, 1), "seg": np.random.randint(0, 2, size=[1, 1, 16, 8, 1]),}, + {"img": np.random.rand(1, 1, 16, 8, 1), "seg": np.random.randint(0, 2, size=[1, 1, 16, 8, 1])}, (1, 1, 16, 8), ] TEST_CASE_4 = [ {"keys": ["img", "seg"]}, - {"img": np.random.rand(1, 2, 1, 3), "seg": np.random.randint(0, 2, size=[1, 2, 1, 3]),}, + {"img": np.random.rand(1, 2, 1, 3), "seg": np.random.randint(0, 2, size=[1, 2, 1, 3])}, (2, 3), ] TEST_CASE_5 = [ {"keys": ["img", "seg"], "dim": -2}, - {"img": np.random.rand(1, 1, 16, 8, 1), "seg": np.random.randint(0, 2, size=[1, 1, 16, 8, 1]),}, + {"img": np.random.rand(1, 1, 16, 8, 1), "seg": np.random.randint(0, 2, size=[1, 1, 16, 8, 1])}, ] TEST_CASE_6 = [ {"keys": ["img", "seg"], "dim": 0.5}, - {"img": np.random.rand(1, 1, 16, 8, 1), "seg": np.random.randint(0, 2, size=[1, 1, 16, 8, 1]),}, + {"img": np.random.rand(1, 1, 16, 8, 1), "seg": np.random.randint(0, 2, size=[1, 1, 16, 8, 1])}, ] diff --git a/tests/test_tversky_loss.py b/tests/test_tversky_loss.py index 783c8a4ac9..3fdefde4d1 100644 --- a/tests/test_tversky_loss.py +++ b/tests/test_tversky_loss.py @@ -17,7 +17,7 @@ from monai.losses import TverskyLoss TEST_CASE_1 = [ # shape: (1, 1, 2, 2), (1, 1, 2, 2) - {"include_background": True, "do_sigmoid": True,}, + {"include_background": True, "do_sigmoid": True}, { "pred": torch.tensor([[[[1.0, -1.0], [-1.0, 1.0]]]]), "ground": torch.tensor([[[[1.0, 0.0], [1.0, 1.0]]]]), @@ -27,7 +27,7 @@ ] TEST_CASE_2 = [ # shape: (2, 1, 2, 2), (2, 1, 2, 2) - {"include_background": True, "do_sigmoid": True,}, + {"include_background": True, "do_sigmoid": True}, { "pred": torch.tensor([[[[1.0, -1.0], [-1.0, 1.0]]], [[[1.0, -1.0], [-1.0, 1.0]]]]), "ground": torch.tensor([[[[1.0, 1.0], [1.0, 1.0]]], [[[1.0, 0.0], [1.0, 0.0]]]]), @@ -37,7 +37,7 @@ ] TEST_CASE_3 = [ # shape: (2, 2, 3), (2, 1, 3) - {"include_background": False, "to_onehot_y": True,}, + {"include_background": False, "to_onehot_y": True}, { "pred": torch.tensor([[[1.0, 1.0, 0.0], [0.0, 0.0, 1.0]], [[1.0, 0.0, 1.0], [0.0, 1.0, 0.0]]]), "ground": torch.tensor([[[0.0, 0.0, 1.0]], [[0.0, 1.0, 0.0]]]), @@ -47,7 +47,7 @@ ] TEST_CASE_4 = [ # shape: (2, 2, 3), (2, 1, 3) - {"include_background": True, "to_onehot_y": True, "do_sigmoid": True,}, + {"include_background": True, "to_onehot_y": True, "do_sigmoid": True}, { "pred": torch.tensor([[[-1.0, 0.0, 1.0], [1.0, 0.0, -1.0]], [[0.0, 0.0, 0.0], [0.0, 0.0, 0.0]]]), "ground": torch.tensor([[[1.0, 0.0, 0.0]], [[1.0, 1.0, 0.0]]]), @@ -57,7 +57,7 @@ ] TEST_CASE_5 = [ # shape: (2, 2, 3), (2, 1, 3) - {"include_background": True, "to_onehot_y": True, "do_softmax": True,}, + {"include_background": True, "to_onehot_y": True, "do_softmax": True}, { "pred": torch.tensor([[[-1.0, 0.0, 1.0], [1.0, 0.0, -1.0]], [[0.0, 0.0, 0.0], [0.0, 0.0, 0.0]]]), "ground": torch.tensor([[[1.0, 0.0, 0.0]], [[1.0, 1.0, 0.0]]]), @@ -67,7 +67,7 @@ ] TEST_CASE_6 = [ # shape: (1, 1, 2, 2), (1, 1, 2, 2) - {"include_background": True, "do_sigmoid": True, "alpha": 0.3, "beta": 0.7,}, + {"include_background": True, "do_sigmoid": True, "alpha": 0.3, "beta": 0.7}, { "pred": torch.tensor([[[[1.0, -1.0], [-1.0, 1.0]]]]), "ground": torch.tensor([[[[1.0, 0.0], [1.0, 1.0]]]]), @@ -77,7 +77,7 @@ ] TEST_CASE_7 = [ # shape: (1, 1, 2, 2), (1, 1, 2, 2) - {"include_background": True, "do_sigmoid": True, "alpha": 0.7, "beta": 0.3,}, + {"include_background": True, "do_sigmoid": True, "alpha": 0.7, "beta": 0.3}, { "pred": torch.tensor([[[[1.0, -1.0], [-1.0, 1.0]]]]), "ground": torch.tensor([[[[1.0, 0.0], [1.0, 1.0]]]]),