예제 #1
0
 def test_ill_opts(self):
     with self.assertRaisesRegex(ValueError, ""):
         MaskedDiceLoss(sigmoid=True, softmax=True)
     chn_input = torch.ones((1, 1, 3))
     chn_target = torch.ones((1, 1, 3))
     with self.assertRaisesRegex(ValueError, ""):
         MaskedDiceLoss(reduction="unknown")(chn_input, chn_target)
     with self.assertRaisesRegex(ValueError, ""):
         MaskedDiceLoss(reduction=None)(chn_input, chn_target)
예제 #2
0
 def test_input_warnings(self):
     chn_input = torch.ones((1, 1, 3))
     chn_target = torch.ones((1, 1, 3))
     with self.assertWarns(Warning):
         loss = MaskedDiceLoss(include_background=False)
         loss.forward(chn_input, chn_target)
     with self.assertWarns(Warning):
         loss = MaskedDiceLoss(softmax=True)
         loss.forward(chn_input, chn_target)
     with self.assertWarns(Warning):
         loss = MaskedDiceLoss(to_onehot_y=True)
         loss.forward(chn_input, chn_target)
예제 #3
0
 def test_ill_shape(self):
     loss = MaskedDiceLoss()
     with self.assertRaisesRegex(AssertionError, ""):
         loss.forward(torch.ones((1, 2, 3)), torch.ones((4, 5, 6)))
예제 #4
0
 def test_shape(self, input_param, input_data, expected_val):
     result = MaskedDiceLoss(**input_param).forward(**input_data)
     np.testing.assert_allclose(result.detach().cpu().numpy(), expected_val, rtol=1e-5)