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
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 13 additions & 19 deletions bfscore.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,24 @@
""" For precision, contours_a==GT & contours_b==Prediction
For recall, contours_a==Prediction & contours_b==GT """


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

top_count = 0
xx = np.array(x)
hits = []
for yrec in y:
d = np.square(xx[:,0] - yrec[0]) + np.square(xx[:,1] - yrec[1])
hits.append(np.any(d < threshold*threshold))
top_count = np.sum(hits)

try:
for b in range(len(contours_b)):

# find the nearest distance
for a in range(len(contours_a)):
dist = (contours_a[a][0] - contours_b[b][0]) * \
(contours_a[a][0] - contours_b[b][0])
dist = dist + \
(contours_a[a][1] - contours_b[b][1]) * \
(contours_a[a][1] - contours_b[b][1])
if dist < threshold*threshold:
top_count = top_count + 1
break

precision_recall = top_count/len(contours_b)
except Exception as e:
precision_recall = top_count / len(y)
except ZeroDivisionError:
precision_recall = 0

return precision_recall, top_count, len(contours_b)
return precision_recall, top_count, len(y)



""" computes the BF (Boundary F1) contour matching score between the predicted and GT segmentation """
Expand Down Expand Up @@ -103,7 +97,7 @@ def bfscore(gtfile, prfile, threshold=2):
if bDebug:
print('contours_gt')
print(contours_gt)

# Get contour area of GT
if contours_gt:
area = cv2.contourArea(np.array(contours_gt))
Expand Down