Skip to content

Commit

Permalink
unblock test_perceptual_loss.py, fixes #6824
Browse files Browse the repository at this point in the history
Signed-off-by: Wenqi Li <[email protected]>

Signed-off-by: Wenqi Li <[email protected]>
  • Loading branch information
wyli authored Aug 7, 2023
1 parent b931e51 commit 52f0493
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions tests/test_perceptual_loss.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

from monai.losses import PerceptualLoss
from monai.utils import optional_import
from tests.utils import SkipIfBeforePyTorchVersion
from tests.utils import SkipIfBeforePyTorchVersion, skip_if_downloading_fails

_, has_torchvision = optional_import("torchvision")
TEST_CASES = [
Expand Down Expand Up @@ -59,13 +59,15 @@ def test_shape(self, input_param, input_shape, target_shape):

@parameterized.expand(TEST_CASES)
def test_identical_input(self, input_param, input_shape, target_shape):
loss = PerceptualLoss(**input_param)
with skip_if_downloading_fails():
loss = PerceptualLoss(**input_param)
tensor = torch.randn(input_shape)
result = loss(tensor, tensor)
self.assertEqual(result, torch.Tensor([0.0]))

def test_different_shape(self):
loss = PerceptualLoss(spatial_dims=2, network_type="squeeze")
with skip_if_downloading_fails():
loss = PerceptualLoss(spatial_dims=2, network_type="squeeze")
tensor = torch.randn(2, 1, 64, 64)
target = torch.randn(2, 1, 32, 32)
with self.assertRaises(ValueError):
Expand Down

0 comments on commit 52f0493

Please sign in to comment.