Commit 2c685655 authored by Rich Munoz's avatar Rich Munoz Committed by TF Object Detection Team
Browse files

Support groundtruth_label_confidences in random_scale_crop_and_pad_to_square

PiperOrigin-RevId: 331247077
parent 84feedee
......@@ -4143,6 +4143,7 @@ def random_scale_crop_and_pad_to_square(
label_weights,
masks=None,
keypoints=None,
label_confidences=None,
scale_min=0.1,
scale_max=2.0,
output_size=512,
......@@ -4176,6 +4177,8 @@ def random_scale_crop_and_pad_to_square(
as the input `image`.
keypoints: (optional) rank 3 float32 tensor with shape [num_instances,
num_keypoints, 2]. The keypoints are in y-x normalized coordinates.
label_confidences: (optional) float32 tensor of shape [num_instance]
representing the confidence for each box.
scale_min: float, the minimum value for the random scale factor.
scale_max: float, the maximum value for the random scale factor.
output_size: int, the desired (square) output image size.
......@@ -4191,9 +4194,8 @@ def random_scale_crop_and_pad_to_square(
label_weights: rank 1 float32 tensor with shape [num_instances].
masks: rank 3 float32 tensor with shape [num_instances, height, width]
containing instance masks.
label_confidences: confidences for retained boxes.
"""
img_shape = tf.shape(image)
input_height, input_width = img_shape[0], img_shape[1]
random_scale = tf.random_uniform([], scale_min, scale_max, seed=seed)
......@@ -4258,6 +4260,9 @@ def random_scale_crop_and_pad_to_square(
keypoints, [0.0, 0.0, 1.0, 1.0])
return_values.append(keypoints)
if label_confidences is not None:
return_values.append(tf.gather(label_confidences, indices))
return return_values
......@@ -4498,7 +4503,7 @@ def get_default_func_arg_map(include_label_weights=True,
fields.InputDataFields.groundtruth_boxes,
fields.InputDataFields.groundtruth_classes,
groundtruth_label_weights, groundtruth_instance_masks,
groundtruth_keypoints),
groundtruth_keypoints, groundtruth_label_confidences),
}
return prep_func_arg_map
......
......@@ -3931,6 +3931,32 @@ class PreprocessorTest(test_case.TestCase, parameterized.TestCase):
self.assertAllClose(image[:, :, 0],
masks[0, :, :])
def test_random_scale_crop_and_pad_to_square_handles_confidences(self):
def graph_fn():
image = tf.zeros([10, 10, 1])
boxes = tf.constant([[0, 0, 0.5, 0.5], [0.5, 0.5, 0.75, 0.75]])
label_weights = tf.constant([1.0, 1.0])
box_labels = tf.constant([0, 1])
box_confidences = tf.constant([-1.0, 1.0])
(_, new_boxes, _, _,
new_confidences) = preprocessor.random_scale_crop_and_pad_to_square(
image,
boxes,
box_labels,
label_weights,
label_confidences=box_confidences,
scale_min=0.8,
scale_max=0.9,
output_size=10)
return new_boxes, new_confidences
boxes, confidences = self.execute_cpu(graph_fn, [])
self.assertLen(boxes, 2)
self.assertAllEqual(confidences, [-1.0, 1.0])
if __name__ == '__main__':
tf.test.main()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment