Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve calc_precision_recall function speed #2

Merged
merged 1 commit into from
Nov 17, 2020
Merged

Improve calc_precision_recall function speed #2

merged 1 commit into from
Nov 17, 2020

Conversation

theodumont
Copy link
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