Args: box_predictions: (..., 4), logits anchors: (..., 4), floatbox. Must have the same shape Returns: box_decoded: (..., 4), float32. With the same shape.
(box_predictions, anchors)
| 25 | |
| 26 | @under_name_scope() |
| 27 | def decode_bbox_target(box_predictions, anchors): |
| 28 | """ |
| 29 | Args: |
| 30 | box_predictions: (..., 4), logits |
| 31 | anchors: (..., 4), floatbox. Must have the same shape |
| 32 | |
| 33 | Returns: |
| 34 | box_decoded: (..., 4), float32. With the same shape. |
| 35 | """ |
| 36 | orig_shape = tf.shape(anchors) |
| 37 | box_pred_txtytwth = tf.reshape(box_predictions, (-1, 2, 2)) |
| 38 | box_pred_txty, box_pred_twth = tf.split(box_pred_txtytwth, 2, axis=1) |
| 39 | # each is (...)x1x2 |
| 40 | anchors_x1y1x2y2 = tf.reshape(anchors, (-1, 2, 2)) |
| 41 | anchors_x1y1, anchors_x2y2 = tf.split(anchors_x1y1x2y2, 2, axis=1) |
| 42 | |
| 43 | waha = anchors_x2y2 - anchors_x1y1 |
| 44 | xaya = (anchors_x2y2 + anchors_x1y1) * 0.5 |
| 45 | |
| 46 | clip = np.log(config.PREPROC.MAX_SIZE / 16.) |
| 47 | wbhb = tf.exp(tf.minimum(box_pred_twth, clip)) * waha |
| 48 | xbyb = box_pred_txty * waha + xaya |
| 49 | x1y1 = xbyb - wbhb * 0.5 |
| 50 | x2y2 = xbyb + wbhb * 0.5 # (...)x1x2 |
| 51 | out = tf.concat([x1y1, x2y2], axis=-2) |
| 52 | return tf.reshape(out, orig_shape) |
| 53 | |
| 54 | |
| 55 | @under_name_scope() |
no test coverage detected
searching dependent graphs…