コード例 #1
0
def parse_predict(predictions):
    """Interpreting the predictions to score classes and boxes.

    Args:
        predictions (np.array): [description]contain all the detections info of a frame.

    Returns:
        [boxes, classes, scores]: the predictions boxes, classes & scores.
    """
    label_classes = cfg['labels_list']

    bbox_regressions, confs = tf.split(predictions[0], [4, -1], -1)
    boxes = decode_bbox_tf(bbox_regressions, priors, cfg['variances'])
    ##classifications shape :(num_priors,num_classes)

    confs = tf.math.softmax(confs, axis=-1)

    out_boxes = []
    out_labels = []
    out_scores = []

    for i in range(1, len(label_classes)):
        cls_scores = confs[:, i]

        score_idx = cls_scores > DETECTION_THRESHOLD

        cls_boxes = boxes[score_idx]
        cls_scores = cls_scores[score_idx]

        nms_idx = compute_nms(cls_boxes, cls_scores, cfg['nms_threshold'],
                              cfg['max_number_keep'])

        cls_boxes = tf.gather(cls_boxes, nms_idx, axis=None)
        cls_scores = tf.gather(cls_scores, nms_idx, axis=None)

        cls_labels = [i] * cls_boxes.shape[0]

        out_boxes.append(cls_boxes)
        out_labels.extend(cls_labels)
        out_scores.append(cls_scores)

    out_boxes = tf.concat(out_boxes, 0)
    out_scores = tf.concat(out_scores, 0)

    boxes = tf.clip_by_value(out_boxes, 0.0, 1.0).numpy()
    classes = np.array(out_labels)

    return boxes, classes, out_scores.numpy()
コード例 #2
0
def parse_predict(predictions, priors, cfg):
    label_classes = cfg['labels_list']

    bbox_regressions, confs = tf.split(predictions[0], [4, -1], axis=-1)
    boxes = decode_bbox_tf(bbox_regressions, priors, cfg['variances'])
    ##classifications shape :(num_priors,num_classes)

    confs = tf.math.softmax(confs, axis=-1)

    out_boxes = []
    out_labels = []
    out_scores = []

    for c in range(1, len(label_classes)):
        cls_scores = confs[:, c]

        score_idx = cls_scores > cfg['score_threshold']

        cls_boxes = boxes[score_idx]
        cls_scores = cls_scores[score_idx]

        nms_idx = compute_nms(cls_boxes, cls_scores, cfg['nms_threshold'],
                              cfg['max_number_keep'])

        cls_boxes = tf.gather(cls_boxes, nms_idx)
        cls_scores = tf.gather(cls_scores, nms_idx)

        cls_labels = [c] * cls_boxes.shape[0]

        out_boxes.append(cls_boxes)
        out_labels.extend(cls_labels)
        out_scores.append(cls_scores)

    out_boxes = tf.concat(out_boxes, axis=0)
    out_scores = tf.concat(out_scores, axis=0)

    boxes = tf.clip_by_value(out_boxes, 0.0, 1.0).numpy()
    classes = np.array(out_labels)
    scores = out_scores.numpy()

    return boxes, classes, scores