def test_sample_based_on_scores_and_distances(self):
     embedding = tf.reshape(self.get_test_embedding(), [-1, 3])
     scores = tf.reshape(self.get_test_semantic_scores(), [-1])
     samples, indices = instance_sampling_utils.sample_based_on_scores_and_distances(
         embedding, scores, 6, 1.0)
     expected_samples = tf.gather(embedding, indices)
     sample_scores = tf.gather(scores, indices)
     self.assertAllClose(expected_samples.numpy(), samples.numpy())
     self.assertAllEqual(indices.shape, np.array([6]))
     self.assertAllEqual(sample_scores.shape, np.array([6]))
def _sample_furthest_voxels(scores, instance_embeddings,
                            num_furthest_voxel_samples,
                            sampler_score_vs_distance_coef):
    """Samples voxels based on distance in embedding space and scores."""
    num_furthest_voxel_samples = tf.minimum(num_furthest_voxel_samples,
                                            tf.shape(scores)[0])
    _, seed_indices = instance_sampling_utils.sample_based_on_scores_and_distances(
        inputs=instance_embeddings,
        scores=tf.reduce_max(scores, axis=1),
        num_samples=num_furthest_voxel_samples,
        scores_coef=sampler_score_vs_distance_coef)
    scores = tf.gather(scores, seed_indices)
    instance_embeddings = tf.gather(instance_embeddings, seed_indices)
    return scores, instance_embeddings
def _sample_furthest_voxels(outputs, num_furthest_voxel_samples,
                            sampler_score_vs_distance_coef):
    """Samples voxels based on distance and scores."""
    num_furthest_voxel_samples = tf.minimum(
        num_furthest_voxel_samples,
        tf.shape(
            outputs[standard_fields.DetectionResultFields.objects_center])[0])
    _, seed_indices = instance_sampling_utils.sample_based_on_scores_and_distances(
        inputs=outputs[standard_fields.DetectionResultFields.objects_center],
        scores=tf.reduce_max(
            outputs[standard_fields.DetectionResultFields.objects_score],
            axis=1),
        num_samples=num_furthest_voxel_samples,
        scores_coef=sampler_score_vs_distance_coef)
    for tensor_name in standard_fields.get_output_object_fields():
        if tensor_name in outputs and outputs[tensor_name] is not None:
            outputs[tensor_name] = tf.gather(outputs[tensor_name],
                                             seed_indices)