Skip to content

Instantly share code, notes, and snippets.

@arthurdouillard
Created June 6, 2018 08:15
Show Gist options
  • Save arthurdouillard/f74efcac217c3b0e836de3cf91adbf4f to your computer and use it in GitHub Desktop.
Save arthurdouillard/f74efcac217c3b0e836de3cf91adbf4f to your computer and use it in GitHub Desktop.
def jaccard(box_a, box_b):
"""box_X is a tuple of the shape (x1, y1, x2, y2)."""
side1 = max(0, min(a[2], b[2]) - max(a[0], b[0]))
side2 = max(0, min(a[3], b[3]) - max(a[1], b[1]))
inter = side1 * side2
area_a = (a[2] - a[0]) * (a[3] - a[1])
area_b = (b[2] - b[0]) * (b[3] - b[1])
union = area_a + area_b - inter
return inter / union
def is_valid(box_pred, box_true, threshold=0.3):
return jaccard(box_red, box_true) >= threshold
@ChubaOraka
Copy link

Looks like

def is_valid(box_pred, box_true, threshold=0.3):
    return jaccard(box_red, box_true) >= threshold

should be

def is_valid(box_red, box_true, threshold=0.3):
    return jaccard(box_red, box_true) >= threshold

i.e. box_red instead of box_pred as the first parameter.

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