Exemple #1
0
    def test_chamfer_distance_evaluate_jacobian(self):
        """Tests the Jacobian of the Chamfer distance loss."""
        point_set_a, point_set_b = _random_point_sets()

        with self.subTest(name="jacobian_wrt_point_set_a"):
            self.assert_jacobian_is_correct_fn(
                lambda x: chamfer_distance.evaluate(x, point_set_b),
                [point_set_a],
                atol=1e-5)

        with self.subTest(name="jacobian_wrt_point_set_b"):
            self.assert_jacobian_is_correct_fn(
                lambda x: chamfer_distance.evaluate(point_set_a, x),
                [point_set_b],
                atol=1e-5)
Exemple #2
0
    def test_evaluate_preset(self, point_set_a, point_set_b,
                             expected_distance):
        tensor_shape = _random_tensor_shape()

        point_set_a = np.tile(point_set_a, tensor_shape + [1, 1])
        point_set_b = np.tile(point_set_b, tensor_shape + [1, 1])
        expected = np.tile(expected_distance, tensor_shape)

        result = chamfer_distance.evaluate(point_set_a, point_set_b)

        self.assertAllClose(expected, result)