Commit ef74806d authored by Frederick Liu's avatar Frederick Liu Committed by A. Unique TensorFlower
Browse files

[vision] Add cycxhwyxyx to box ops.

PiperOrigin-RevId: 387159154
parent 9465aa0e
...@@ -78,6 +78,32 @@ def yxyx_to_cycxhw(boxes): ...@@ -78,6 +78,32 @@ def yxyx_to_cycxhw(boxes):
return new_boxes return new_boxes
def cycxhw_to_yxyx(boxes):
"""Converts box center coordinates plus height and width terms to corner.
Args:
boxes: a numpy array whose last dimension is 4 representing the coordinates
of boxes in cy, cx, height, width order.
Returns:
boxes: a numpy array whose shape is the same as `boxes` in new format.
Raises:
ValueError: If the last dimension of boxes is not 4.
"""
if boxes.shape[-1] != 4:
raise ValueError(
'boxes.shape[-1] is {:d}, but must be 4.'.format(boxes.shape[-1]))
boxes_ymin = boxes[..., 0] - boxes[..., 2] / 2
boxes_xmin = boxes[..., 1] - boxes[..., 3] / 2
boxes_ymax = boxes[..., 0] + boxes[..., 2] / 2
boxes_xmax = boxes[..., 1] + boxes[..., 3] / 2
new_boxes = tf.stack([
boxes_ymin, boxes_xmin, boxes_ymax, boxes_xmax], axis=-1)
return new_boxes
def jitter_boxes(boxes, noise_scale=0.025): def jitter_boxes(boxes, noise_scale=0.025):
"""Jitter the box coordinates by some noise distribution. """Jitter the box coordinates by some noise distribution.
......
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