MCPcopy Index your code
hub / github.com/tensorpack/tensorpack / encode_bbox_target

Function encode_bbox_target

examples/FasterRCNN/modeling/model_box.py:56–79  ·  view source on GitHub ↗

Args: boxes: (..., 4), float32 anchors: (..., 4), float32 Returns: box_encoded: (..., 4), float32 with the same shape.

(boxes, anchors)

Source from the content-addressed store, hash-verified

54
55@under_name_scope()
56def encode_bbox_target(boxes, anchors):
57 """
58 Args:
59 boxes: (..., 4), float32
60 anchors: (..., 4), float32
61
62 Returns:
63 box_encoded: (..., 4), float32 with the same shape.
64 """
65 anchors_x1y1x2y2 = tf.reshape(anchors, (-1, 2, 2))
66 anchors_x1y1, anchors_x2y2 = tf.split(anchors_x1y1x2y2, 2, axis=1)
67 waha = anchors_x2y2 - anchors_x1y1
68 xaya = (anchors_x2y2 + anchors_x1y1) * 0.5
69
70 boxes_x1y1x2y2 = tf.reshape(boxes, (-1, 2, 2))
71 boxes_x1y1, boxes_x2y2 = tf.split(boxes_x1y1x2y2, 2, axis=1)
72 wbhb = boxes_x2y2 - boxes_x1y1
73 xbyb = (boxes_x2y2 + boxes_x1y1) * 0.5
74
75 # Note that here not all boxes are valid. Some may be zero
76 txty = (xbyb - xaya) / waha
77 twth = tf.math.log(wbhb / waha) # may contain -inf for invalid boxes
78 encoded = tf.concat([txty, twth], axis=1) # (-1x2x2)
79 return tf.reshape(encoded, tf.shape(boxes))
80
81
82@under_name_scope()

Callers 2

lossesMethod · 0.85
encoded_gt_boxesMethod · 0.85

Calls 2

shapeMethod · 0.80
logMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…