Пример #1
0
 def test_weighted_sampler_negative_weights(self):
     """Test for exception with negative weights."""
     vertices, faces = mesh_test_utils.create_square_triangle_mesh()
     face_wts = np.array([-0.3, 0.1, 0.5, 0.6], dtype=np.float32)
     num_samples = 10
     error_msg = "Condition x >= y did not hold."
     with self.assertRaisesRegexp(tf.errors.InvalidArgumentError,
                                  error_msg):
         sampler.weighted_random_sample_triangle_mesh(vertices,
                                                      faces,
                                                      num_samples,
                                                      face_weights=face_wts)
Пример #2
0
 def sampler_fn(vertices):
     sample_pts, _ = sampler.weighted_random_sample_triangle_mesh(
         vertices,
         index_tensor,
         num_samples,
         weights_tensor,
         seed=[0, 1],
         stateless=True)
     return sample_pts
Пример #3
0
    def test_weighted_random_sample(self):
        """Test for provided face weights."""
        faces = np.array([[0, 1, 2], [2, 1, 3]], dtype=np.int32)
        vertex_attributes = np.array([[0.], [0.], [1.], [1.]],
                                     dtype=np.float32)

        # Equal face weights, mean of sampled attributes = 0.5.
        expected_mean = np.array([0.5], dtype=np.float32)
        sample_pts, _ = sampler.weighted_random_sample_triangle_mesh(
            vertex_attributes,
            faces,
            num_samples=1000000,
            face_weights=(0.5, 0.5))
        self.assertAllClose(expected_mean,
                            tf.reduce_mean(input_tensor=sample_pts, axis=-2),
                            atol=1e-3)
        # Face weights biased towards second face, mean > 0.5
        sample_pts, _ = sampler.weighted_random_sample_triangle_mesh(
            vertex_attributes,
            faces,
            num_samples=1000000,
            face_weights=(0.2, 0.8))
        self.assertGreater(tf.reduce_mean(input_tensor=sample_pts, axis=-2),
                           expected_mean)