"...resnet50_tensorflow.git" did not exist on "17ba1ca49db57ec2dd8b16b18bbcf68c995bf102"
Commit f7b4c6de authored by Vivek Rathod's avatar Vivek Rathod Committed by TF Object Detection Team
Browse files

Avoid explicit tf.unstack in...

Avoid  explicit tf.unstack in `convert_strided_predictions_to_normalized_boxes`. This enables exporting a saved model with dynamic batch size.

PiperOrigin-RevId: 345055072
parent bd217c64
...@@ -1007,27 +1007,12 @@ def convert_strided_predictions_to_normalized_boxes(boxes, stride, ...@@ -1007,27 +1007,12 @@ def convert_strided_predictions_to_normalized_boxes(boxes, stride,
boxes: A tensor of shape [batch_size, num_boxes, 4] representing the boxes: A tensor of shape [batch_size, num_boxes, 4] representing the
coordinates of the normalized boxes. coordinates of the normalized boxes.
""" """
# Note: We use tf ops instead of functions in box_list_ops to make this
def _normalize_boxlist(args): # function compatible with dynamic batch size.
boxes = boxes * stride
boxes, height, width = args true_image_shapes = tf.tile(true_image_shapes[:, tf.newaxis, :2], [1, 1, 2])
boxes = box_list_ops.scale(boxes, stride, stride) boxes = boxes / tf.cast(true_image_shapes, tf.float32)
boxes = box_list_ops.to_normalized_coordinates(boxes, height, width) boxes = tf.clip_by_value(boxes, 0.0, 1.0)
boxes = box_list_ops.clip_to_window(boxes, [0., 0., 1., 1.],
filter_nonoverlapping=False)
return boxes
box_lists = [box_list.BoxList(boxes) for boxes in tf.unstack(boxes, axis=0)]
true_heights, true_widths, _ = tf.unstack(true_image_shapes, axis=1)
true_heights_list = tf.unstack(true_heights, axis=0)
true_widths_list = tf.unstack(true_widths, axis=0)
box_lists = list(map(_normalize_boxlist,
zip(box_lists, true_heights_list, true_widths_list)))
boxes = tf.stack([box_list_instance.get() for
box_list_instance in box_lists], axis=0)
return boxes return boxes
......
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