'Decode relative codes to boxes and keypoints.
Args:
rel_codes: a tensor with shape [N, 4 + 2 * num_keypoints] representing N
anchor-encoded boxes and keypoints
anchors: BoxList of anchors.
Returns:
boxes: BoxList holding N bounding boxes and keypoints.'

def _decode(self, rel_codes, anchors):

    (ycenter_a, xcenter_a, ha, wa) = anchors.get_center_coordinates_and_sizes()
    num_codes = tf.shape(rel_codes)[0]
    result = tf.unstack(tf.transpose(rel_codes))
    (ty, tx, th, tw) = result[:4]
    tkeypoints = result[4:]
    if self._scale_factors:
        ty /= self._scale_factors[0]
        tx /= self._scale_factors[1]
        th /= self._scale_factors[2]
        tw /= self._scale_factors[3]
        tkeypoints /= tf.tile(self._keypoint_scale_factors, [1, num_codes])
    w = (tf.exp(tw) * wa)
    h = (tf.exp(th) * ha)
    ycenter = ((ty * ha) + ycenter_a)
    xcenter = ((tx * wa) + xcenter_a)
    ymin = (ycenter - (h / 2.0))
    xmin = (xcenter - (w / 2.0))
    ymax = (ycenter + (h / 2.0))
    xmax = (xcenter + (w / 2.0))
    decoded_boxes_keypoints = box_list.BoxList(tf.transpose(tf.stack([ymin, xmin, ymax, xmax])))
    tiled_anchor_centers = tf.tile(tf.stack([ycenter_a, xcenter_a]), [self._num_keypoints, 1])
    tiled_anchor_sizes = tf.tile(tf.stack([ha, wa]), [self._num_keypoints, 1])
    keypoints = ((tkeypoints * tiled_anchor_sizes) + tiled_anchor_centers)
    keypoints = tf.reshape(tf.transpose(keypoints), [(-1), self._num_keypoints, 2])
    decoded_boxes_keypoints.add_field(fields.BoxListFields.keypoints, keypoints)
    return decoded_boxes_keypoints
