Skip to content

Fast version #1

Description

@bpfliegel

Dude, the prec/recall function is very slow. Use numpy if possible for batch calculations:

def calc_precision_recall(contours_a, contours_b, threshold):
        x = contours_a
        y = contours_b

        t1 = np.tile(x, (len(y),1))
        t2 = np.repeat(y, len(x), axis=0)
        t = np.concatenate( (t1,t2), axis=1)

        dx = (t[...,0] - t[...,2]) * (t[...,0] - t[...,2])
        dy = (t[...,1] - t[...,3]) * (t[...,1] - t[...,3])
        thr = (dx + dy) < (threshold * threshold)

        blocks = np.split(thr, len(y))
        block_has_hit = [np.any(x == True) for x in blocks]
        top_count = np.sum(block_has_hit)

        precision_recall = top_count/len(y)
        return precision_recall, top_count, len(y)

It should be the same, you can validate it with your own data.
Thanks, Balint

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions