Skip to content

Commit

Permalink
fixes unit tests
Browse files Browse the repository at this point in the history
Signed-off-by: Wenqi Li <wenqil@nvidia.com>
  • Loading branch information
wyli committed Feb 1, 2021
1 parent 9115b74 commit cd500e9
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion monai/data/png_saver.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def save(self, data: Union[torch.Tensor, np.ndarray], meta_data: Optional[Dict]
if data.shape[0] == 1:
data = data.squeeze(0)
elif 2 < data.shape[0] < 5:
data = np.moveaxis(data, 0, -1) # type: ignore
data = np.moveaxis(np.asarray(data), 0, -1)
else:
raise ValueError(f"Unsupported number of channels: {data.shape[0]}, available options are [1, 3, 4]")

Expand Down
4 changes: 2 additions & 2 deletions monai/networks/nets/varautoencoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def __init__(
self.in_channels, *self.in_shape = in_shape

self.latent_size = latent_size
self.final_size = np.asarray(self.in_shape, int)
self.final_size = np.asarray(self.in_shape, dtype=int)

super().__init__(
dimensions,
Expand All @@ -68,7 +68,7 @@ def __init__(
padding = same_padding(self.kernel_size)

for s in strides:
self.final_size = np.asarray(calculate_out_shape(self.final_size, self.kernel_size, s, padding), dtype=int)
self.final_size = calculate_out_shape(self.final_size, self.kernel_size, s, padding) # type: ignore

linear_size = int(np.product(self.final_size)) * self.encoded_channels
self.mu = nn.Linear(linear_size, self.latent_size)
Expand Down
8 changes: 4 additions & 4 deletions tests/test_crop_foregroundd.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,14 @@ def test_value(self, argments, image, expected_data):
@parameterized.expand([TEST_CASE_1])
def test_foreground_position(self, argments, image, _):
result = CropForegroundd(**argments)(image)
self.assertListEqual(result["foreground_start_coord"], [1, 1])
self.assertListEqual(result["foreground_end_coord"], [4, 4])
np.testing.assert_allclose(result["foreground_start_coord"], np.array([1, 1]))
np.testing.assert_allclose(result["foreground_end_coord"], np.array([4, 4]))

argments["start_coord_key"] = "test_start_coord"
argments["end_coord_key"] = "test_end_coord"
result = CropForegroundd(**argments)(image)
self.assertListEqual(result["test_start_coord"], [1, 1])
self.assertListEqual(result["test_end_coord"], [4, 4])
np.testing.assert_allclose(result["test_start_coord"], np.array([1, 1]))
np.testing.assert_allclose(result["test_end_coord"], np.array([4, 4]))


if __name__ == "__main__":
Expand Down

0 comments on commit cd500e9

Please sign in to comment.