def fastrcnn_predictions(boxes, scores):
    """
    Generate final results from predictions of all proposals.

    Args:
        boxes: n#classx4 floatbox in float32
        scores: nx#class

    Returns:
        boxes: Kx4
        scores: K
        labels: K
    """
    assert boxes.shape[1] == scores.shape[1]
    boxes = tf.transpose(boxes, [1, 0, 2])[1:, :, :]  # #catxnx4
    scores = tf.transpose(scores[:, 1:], [1, 0])  # #catxn

    max_coord = tf.reduce_max(boxes)
    filtered_ids = tf.where(scores > cfg.TEST.RESULT_SCORE_THRESH)  # Fx2
    filtered_boxes = tf.gather_nd(boxes, filtered_ids)  # Fx4
    filtered_scores = tf.gather_nd(scores, filtered_ids)  # F,
    cls_per_box = tf.slice(filtered_ids, [0, 0], [-1, 1])
    offsets = tf.cast(cls_per_box, tf.float32) * (max_coord + 1)  # F,1
    nms_boxes = filtered_boxes + offsets
    selection = tf.image.non_max_suppression(
        nms_boxes,
        filtered_scores,
        cfg.TEST.RESULTS_PER_IM,
        cfg.TEST.FRCNN_NMS_THRESH)
    final_scores = tf.gather(filtered_scores, selection, name='scores')
    final_labels = tf.add(tf.gather(cls_per_box[:, 0], selection), 1, name='labels')
    final_boxes = tf.gather(filtered_boxes, selection, name='boxes')
    return final_boxes, final_scores, final_labels

    Generate final results from predictions of all proposals.

    Args:
        boxes: n#classx4 floatbox in float32
        scores: nx#class

    Returns:
        boxes: Kx4
        scores: K
        labels: K
    
examples/FasterRCNN/modeling/model_frcnn.py