def calc_pr_ovr_noref()

in utils/utils.py [0:0]


def calc_pr_ovr_noref(counts, out):
    """
  [P, R, score, ap] = calc_pr_ovr(counts, out, K)
  Input    :
    counts : number of occurrences of this word in the ith image
    out    : score for this image
  Output   :
    P, R   : precision and recall
    score  : score which corresponds to the particular precision and recall
    ap     : average precision
  """
    #binarize counts
    out = out.astype(np.float64)
    counts = np.array(counts > 0, dtype=np.float32)
    tog = np.hstack((counts[:, np.newaxis].astype(np.float64),
                     out[:, np.newaxis].astype(np.float64)))
    ind = np.argsort(out)
    ind = ind[::-1]
    score = np.array([tog[i, 1] for i in ind])
    sortcounts = np.array([tog[i, 0] for i in ind])

    tp = sortcounts
    fp = sortcounts.copy()
    for i in range(sortcounts.shape[0]):
        if sortcounts[i] >= 1:
            fp[i] = 0.
        elif sortcounts[i] < 1:
            fp[i] = 1.

    tp = np.cumsum(tp)
    fp = np.cumsum(fp)
    # P = np.cumsum(tp)/(np.cumsum(tp) + np.cumsum(fp));
    P = tp / np.maximum(tp + fp, np.finfo(np.float64).eps)

    numinst = np.sum(counts)

    R = tp / (numinst + 1e-10)

    ap = voc_ap(R, P)
    return P, R, score, ap