'Converts predictions from the second stage box classifier to detections.
Args:
refined_box_encodings: a 3-D tensor with shape
[total_num_padded_proposals, num_classes, 4] representing predicted
(final) refined box encodings.
class_predictions_with_background: a 3-D tensor with shape
[total_num_padded_proposals, num_classes + 1] containing class
predictions (logits) for each of the proposals.  Note that this tensor
*includes* background class predictions (at class index 0).
proposal_boxes: [batch_size, self.max_num_proposals, 4] representing
decoded proposal bounding boxes.
num_proposals: A Tensor of type `int32`. A 1-D tensor of shape [batch]
representing the number of proposals predicted for each image in
the batch.
image_shape: a 1-D tensor representing the input image shape.
mask_predictions: (optional) a 4-D tensor with shape
[total_num_padded_proposals, num_classes, mask_height, mask_width]
containing instance mask predictions.
mask_threshold: a scalar threshold determining which mask values are
rounded to 0 or 1.
Returns:
A dictionary containing:
`detection_boxes`: [batch, max_detection, 4]
`detection_scores`: [batch, max_detections]
`detection_classes`: [batch, max_detections]
`num_detections`: [batch]
`detection_masks`:
(optional) [batch, max_detections, mask_height, mask_width]'

def _postprocess_box_classifier(self, refined_box_encodings, class_predictions_with_background, proposal_boxes, num_proposals, image_shape, mask_predictions=None, mask_threshold=0.5):

    refined_box_encodings_batch = tf.reshape(refined_box_encodings, [(-1), self.max_num_proposals, self.num_classes, self._box_coder.code_size])
    class_predictions_with_background_batch = tf.reshape(class_predictions_with_background, [(-1), self.max_num_proposals, (self.num_classes + 1)])
    refined_decoded_boxes_batch = self._batch_decode_boxes(refined_box_encodings_batch, proposal_boxes)
    class_predictions_with_background_batch = self._second_stage_score_conversion_fn(class_predictions_with_background_batch)
    class_predictions_batch = tf.reshape(tf.slice(class_predictions_with_background_batch, [0, 0, 1], [(-1), (-1), (-1)]), [(-1), self.max_num_proposals, self.num_classes])
    clip_window = tf.to_float(tf.stack([0, 0, image_shape[1], image_shape[2]]))
    mask_predictions_batch = None
    if (mask_predictions is not None):
        mask_height = mask_predictions.shape[2].value
        mask_width = mask_predictions.shape[3].value
        mask_predictions_batch = tf.reshape(mask_predictions, [(-1), self.max_num_proposals, self.num_classes, mask_height, mask_width])
    (nmsed_boxes, nmsed_scores, nmsed_classes, nmsed_masks, num_detections) = self._second_stage_nms_fn(refined_decoded_boxes_batch, class_predictions_batch, clip_window=clip_window, change_coordinate_frame=True, num_valid_boxes=num_proposals, masks=mask_predictions_batch)
    detections = {'detection_boxes': nmsed_boxes, 'detection_scores': nmsed_scores, 'detection_classes': nmsed_classes, 'num_detections': tf.to_float(num_detections)}
    if (nmsed_masks is not None):
        detections['detection_masks'] = nmsed_masks
    if (mask_predictions is not None):
        detections['detection_masks'] = tf.to_float(tf.greater_equal(detections['detection_masks'], mask_threshold))
    return detections
