def test_value(self, input_data, expected_value):
     percentile = None
     if len(input_data) == 3:
         [seg_1, seg_2, percentile] = input_data
     else:
         [seg_1, seg_2] = input_data
     ct = 0
     seg_1 = torch.tensor(seg_1)
     seg_2 = torch.tensor(seg_2)
     for metric in ["euclidean", "chessboard", "taxicab"]:
         for directed in [True, False]:
             hd_metric = HausdorffDistanceMetric(include_background=False,
                                                 distance_metric=metric,
                                                 percentile=percentile,
                                                 directed=directed)
             # shape of seg_1, seg_2 are: HWD, converts to BNHWD
             batch, n_class = 2, 3
             batch_seg_1 = seg_1.unsqueeze(0).unsqueeze(0).repeat(
                 [batch, n_class, 1, 1, 1])
             batch_seg_2 = seg_2.unsqueeze(0).unsqueeze(0).repeat(
                 [batch, n_class, 1, 1, 1])
             hd_metric(batch_seg_1, batch_seg_2)
             result = hd_metric.aggregate()
             expected_value_curr = expected_value[ct]
             np.testing.assert_allclose(expected_value_curr,
                                        result,
                                        rtol=1e-7)
             ct += 1
示例#2
0
 def test_nans(self, input_data):
     [seg_1, seg_2] = input_data
     seg_1 = torch.tensor(seg_1)
     seg_2 = torch.tensor(seg_2)
     hd_metric = HausdorffDistanceMetric(include_background=False, get_not_nans=True)
     batch_seg_1 = seg_1.unsqueeze(0).unsqueeze(0)
     batch_seg_2 = seg_2.unsqueeze(0).unsqueeze(0)
     hd_metric(batch_seg_1, batch_seg_2)
     result, not_nans = hd_metric.aggregate()
     np.testing.assert_allclose(0, result, rtol=1e-7)
     np.testing.assert_allclose(0, not_nans, rtol=1e-7)