'Decode tensor of refined box encodings.
Args:
refined_box_encodings: a 3-D tensor with shape
[batch_size, max_num_proposals, num_classes, self._box_coder.code_size]
representing predicted (final) refined box encodings.
proposal_boxes: [batch_size, self.max_num_proposals, 4] representing
decoded proposal bounding boxes.
Returns:
refined_box_predictions: a [batch_size, max_num_proposals, num_classes, 4]
float tensor representing (padded) refined bounding box predictions
(for each image in batch, proposal and class).'

def _batch_decode_boxes(self, box_encodings, anchor_boxes):

    'Decodes    box    encodings    with    respect    to    the    anchor    boxes.\n\n                Args:\n                        box_encodings:    a    4-D    tensor    with    shape\n                                [batch_size,    num_anchors,    num_classes,    self._box_coder.code_size]\n                                representing    box    encodings.\n                        anchor_boxes:    [batch_size,    num_anchors,    4]    representing\n                                decoded    bounding    boxes.\n\n                Returns:\n                        decoded_boxes:    a    [batch_size,    num_anchors,    num_classes,    4]\n                                float    tensor    representing    bounding    box    predictions\n                                (for    each    image    in    batch,    proposal    and    class).\n                '
    combined_shape = shape_utils.combined_static_and_dynamic_shape(box_encodings)
    num_classes = combined_shape[2]
    tiled_anchor_boxes = tf.tile(tf.expand_dims(anchor_boxes, 2), [1, 1, num_classes, 1])
    tiled_anchors_boxlist = box_list.BoxList(tf.reshape(tiled_anchor_boxes, [(-1), 4]))
    decoded_boxes = self._box_coder.decode(tf.reshape(box_encodings, [(-1), self._box_coder.code_size]), tiled_anchors_boxlist)
    return tf.reshape(decoded_boxes.get(), tf.stack([combined_shape[0], combined_shape[1], num_classes, 4]))
