-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathutil.py
31 lines (21 loc) · 884 Bytes
/
util.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import math
import tensorflow as tf
def iou(box1, box2):
'''Caclulate IoU of two boxes'''
x11, y11, w1, h1 = box1
x12, y12 = x11 + w1, y11 + h1
x21, y21, w2, h2 = box2
x22, y22 = x21 + w2, y21 + h2
x_overlap = max(0, min(x12, x22) - max(x11, x21))
y_overlap = max(0, min(y12, y22) - max(y11, y21))
intersection = x_overlap * y_overlap
return 1. * intersection / (w1 * h1 + w2 * h2 - intersection)
def tf_iou(box1, box2):
x11, y11, w1, h1 = tf.split(0, 4, box1)
x12, y12 = x11 + w1, y11 + h1
x21, y21, w2, h2 = tf.split(0, 4, box2)
x22, y22 = x21 + w2, y21 + h2
x_overlap = tf.maximum(0.0, tf.minimum(x12, x22) - tf.maximum(x11, x21))
y_overlap = tf.maximum(0.0, tf.minimum(y12, y22) - tf.maximum(y11, y21))
intersection = x_overlap * y_overlap
return 1. * intersection / (w1 * h1 + w2 * h2 - intersection)