Skip to content

Commit

Permalink
fixes trailing comma, cf psf/black#1289
Browse files Browse the repository at this point in the history
  • Loading branch information
wyli committed May 5, 2020
1 parent 6533b86 commit 3a20df6
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 41 deletions.
8 changes: 4 additions & 4 deletions monai/transforms/utils.py
Expand Up @@ -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

Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_crop_foreground.py
Expand Up @@ -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 = [
Expand All @@ -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 = [
Expand Down
4 changes: 2 additions & 2 deletions tests/test_crop_foregroundd.py
Expand Up @@ -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 = [
Expand All @@ -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 = [
Expand Down
16 changes: 8 additions & 8 deletions tests/test_dice_loss.py
Expand Up @@ -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]]]]),
Expand All @@ -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]]]]),
Expand All @@ -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]]]),
Expand All @@ -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]]]),
Expand All @@ -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]]]),
Expand All @@ -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]]]]),
Expand All @@ -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]]]]),
Expand All @@ -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]]]]),
Expand Down
14 changes: 7 additions & 7 deletions tests/test_generalized_dice_loss.py
Expand Up @@ -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]]]]),
Expand All @@ -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]]]]),
Expand All @@ -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]]]),
Expand All @@ -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]]]),
Expand All @@ -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]]]),
Expand All @@ -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]]]),
Expand All @@ -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]]]]),
Expand Down
8 changes: 4 additions & 4 deletions tests/test_highresnet.py
Expand Up @@ -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),
]
Expand Down
2 changes: 1 addition & 1 deletion tests/test_spacing.py
Expand Up @@ -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)),
],
[
Expand Down
12 changes: 6 additions & 6 deletions tests/test_squeezedimd.py
Expand Up @@ -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])},
]


Expand Down
14 changes: 7 additions & 7 deletions tests/test_tversky_loss.py
Expand Up @@ -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]]]]),
Expand All @@ -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]]]]),
Expand All @@ -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]]]),
Expand All @@ -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]]]),
Expand All @@ -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]]]),
Expand All @@ -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]]]]),
Expand All @@ -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]]]]),
Expand Down

0 comments on commit 3a20df6

Please sign in to comment.