Skip to content

Improve calc_precision_recall function speed#2

Merged
minar09 merged 1 commit into
minar09:masterfrom
theodumont:pr-faster-with-numpy
Nov 17, 2020
Merged

Improve calc_precision_recall function speed#2
minar09 merged 1 commit into
minar09:masterfrom
theodumont:pr-faster-with-numpy

Conversation

@theodumont
Copy link
Copy Markdown
Contributor

@theodumont theodumont commented Nov 17, 2020

As suggested in #1, this PR improves calc_precision_recall speed using numpy. Fix #1.

Minor additions to #1 version

  • added a try/except to catch ZeroDivisionError
  • use np.any(d < threshold*threshold) to produce exact same output as original function

Benchmark

A quick benchmark to see how it improved speed

from time import time
t0 = time()
for _ in range(1000):
    calc_precision_recall(contours_gt, contours_pr, threshold)
print(f"Executed in {time()-t0:.2f}s.")

gives

# original function
Executed in 60.53s.
# with numpy
Executed in 5.45s.

Thanks!

@theodumont theodumont mentioned this pull request Nov 17, 2020
@minar09 minar09 merged commit 3a336f5 into minar09:master Nov 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fast version

2 participants