Exemplo n.º 1
0
 def test_ill_shape(self):
     loss = BendingEnergyLoss()
     # not in 3-d, 4-d, 5-d
     with self.assertRaisesRegex(ValueError, ""):
         loss.forward(torch.ones((1, 3)))
     with self.assertRaisesRegex(ValueError, ""):
         loss.forward(torch.ones((1, 3, 5, 5, 5, 5)))
     # spatial_dim < 5
     with self.assertRaisesRegex(ValueError, ""):
         loss.forward(torch.ones((1, 3, 4, 5, 5)))
     with self.assertRaisesRegex(ValueError, ""):
         loss.forward(torch.ones((1, 3, 5, 4, 5)))
     with self.assertRaisesRegex(ValueError, ""):
         loss.forward(torch.ones((1, 3, 5, 5, 4)))
Exemplo n.º 2
0
    def test_ill_shape(self):
        loss = BendingEnergyLoss()
        # not in 3-d, 4-d, 5-d
        with self.assertRaisesRegex(ValueError, "Expecting 3-d, 4-d or 5-d"):
            loss.forward(torch.ones((1, 3), device=device))
        with self.assertRaisesRegex(ValueError, "Expecting 3-d, 4-d or 5-d"):
            loss.forward(torch.ones((1, 4, 5, 5, 5, 5), device=device))
        with self.assertRaisesRegex(ValueError, "All spatial dimensions"):
            loss.forward(torch.ones((1, 3, 4, 5, 5), device=device))
        with self.assertRaisesRegex(ValueError, "All spatial dimensions"):
            loss.forward(torch.ones((1, 3, 5, 4, 5)))
        with self.assertRaisesRegex(ValueError, "All spatial dimensions"):
            loss.forward(torch.ones((1, 3, 5, 5, 4)))

        # number of vector components unequal to number of spatial dims
        with self.assertRaisesRegex(ValueError, "Number of vector components"):
            loss.forward(torch.ones((1, 2, 5, 5, 5)))
        with self.assertRaisesRegex(ValueError, "Number of vector components"):
            loss.forward(torch.ones((1, 2, 5, 5, 5)))