"...models/git@developer.sourcefind.cn:OpenDAS/vision.git" did not exist on "bb3aae7b2543637191ad9c810f082eae622534b8"
Commit cabd4d16 authored by Kaushik Shivakumar's avatar Kaushik Shivakumar
Browse files

clean up and improve tests

parent e0e440e1
...@@ -327,7 +327,7 @@ def l1(boxlist1, boxlist2, scope=None): ...@@ -327,7 +327,7 @@ def l1(boxlist1, boxlist2, scope=None):
tf.transpose(w1), axis=1)) tf.transpose(w1), axis=1))
return ycenters + xcenters + heights + widths return ycenters + xcenters + heights + widths
def giou_loss(boxlist1, boxlist2, scope=None): def giou(boxlist1, boxlist2, scope=None):
""" """
Computes generalized IOU loss between two boxlists pairwise, Computes generalized IOU loss between two boxlists pairwise,
as described at giou.stanford.edu. as described at giou.stanford.edu.
...@@ -345,7 +345,7 @@ def giou_loss(boxlist1, boxlist2, scope=None): ...@@ -345,7 +345,7 @@ def giou_loss(boxlist1, boxlist2, scope=None):
M = boxlist2.num_boxes() M = boxlist2.num_boxes()
boxes1 = tf.repeat(boxlist1.get(), repeats=M, axis=0) boxes1 = tf.repeat(boxlist1.get(), repeats=M, axis=0)
boxes2 = tf.tile(boxlist2.get(), multiples=[N, 1]) boxes2 = tf.tile(boxlist2.get(), multiples=[N, 1])
return tf.reshape(1.0 - ops.giou(boxes1, boxes2), [N, M]) return tf.reshape(ops.giou(boxes1, boxes2), [N, M])
def matched_iou(boxlist1, boxlist2, scope=None): def matched_iou(boxlist1, boxlist2, scope=None):
"""Compute intersection-over-union between corresponding boxes in boxlists. """Compute intersection-over-union between corresponding boxes in boxlists.
......
...@@ -247,9 +247,9 @@ class BoxListOpsTest(test_case.TestCase): ...@@ -247,9 +247,9 @@ class BoxListOpsTest(test_case.TestCase):
corners2 = tf.constant([[5.0, 7.0, 7.0, 9.0], [5.0, 11.0, 7.0, 13.0]]) corners2 = tf.constant([[5.0, 7.0, 7.0, 9.0], [5.0, 11.0, 7.0, 13.0]])
boxes1 = box_list.BoxList(corners1) boxes1 = box_list.BoxList(corners1)
boxes2 = box_list.BoxList(corners2) boxes2 = box_list.BoxList(corners2)
giou = box_list_ops.giou_loss(boxes1, boxes2) giou = box_list_ops.giou(boxes1, boxes2)
return giou return giou
exp_output = [[0.0, 4.0 / 3.0]] exp_output = [[1.0, -1.0 / 3.0]]
giou_output = self.execute(graph_fn, []) giou_output = self.execute(graph_fn, [])
self.assertAllClose(giou_output, exp_output) self.assertAllClose(giou_output, exp_output)
......
...@@ -1631,19 +1631,19 @@ class TestGatherWithPaddingValues(test_case.TestCase): ...@@ -1631,19 +1631,19 @@ class TestGatherWithPaddingValues(test_case.TestCase):
class TestGIoU(test_case.TestCase): class TestGIoU(test_case.TestCase):
def test_giou_general(self): def test_giou_with_no_overlap(self):
expected_giou_tensor = [ expected_giou_tensor = [
0, -1/3, 1/25, -3/4, 0, -98/100 0, -1/3, -3/4, 0, -98/100
] ]
def graph_fn(): def graph_fn():
boxes1 = tf.constant([[3, 4, 5, 6], [3, 3, 5, 5], boxes1 = tf.constant([[3, 4, 5, 6], [3, 3, 5, 5],
[2, 1, 7, 6], [0, 0, 0, 0], [0, 0, 0, 0], [3, 3, 5, 5],
[3, 3, 5, 5], [9, 9, 10, 10]], [9, 9, 10, 10]],
dtype=tf.float32) dtype=tf.float32)
boxes2 = tf.constant([[3, 2, 5, 4], [3, 7, 5, 9], boxes2 = tf.constant([[3, 2, 5, 4], [3, 7, 5, 9],
[4, 3, 5, 4], [5, 5, 10, 10], [5, 5, 10, 10], [3, 5, 5, 7],
[3, 5, 5, 7], [0, 0, 1, 1]], dtype=tf.float32) [0, 0, 1, 1]], dtype=tf.float32)
giou = ops.giou(boxes1, boxes2) giou = ops.giou(boxes1, boxes2)
self.assertEqual(giou.dtype, tf.float32) self.assertEqual(giou.dtype, tf.float32)
...@@ -1653,15 +1653,50 @@ class TestGIoU(test_case.TestCase): ...@@ -1653,15 +1653,50 @@ class TestGIoU(test_case.TestCase):
giou = self.execute(graph_fn, []) giou = self.execute(graph_fn, [])
self.assertAllClose(expected_giou_tensor, giou) self.assertAllClose(expected_giou_tensor, giou)
def test_giou_edge_cases(self): def test_giou_with_overlaps(self):
expected_giou_tensor = [ expected_giou_tensor = [
1, 0 1/25, 1/4, 1/3, 1/7 - 2/9
] ]
def graph_fn(): def graph_fn():
boxes1 = tf.constant([[3, 3, 5, 5], [1, 1, 1, 1]], boxes1 = tf.constant([[2, 1, 7, 6], [2, 2, 4, 4],
[2, 2, 4, 4], [2, 2, 4, 4]],
dtype=tf.float32)
boxes2 = tf.constant([[4, 3, 5, 4], [3, 3, 4, 4],
[2, 3, 4, 5], [3, 3, 5, 5]], dtype=tf.float32)
giou = ops.giou(boxes1, boxes2)
self.assertEqual(giou.dtype, tf.float32)
return giou
giou = self.execute(graph_fn, [])
self.assertAllClose(expected_giou_tensor, giou)
def test_giou_with_perfect_overlap(self):
expected_giou_tensor = [1]
def graph_fn():
boxes1 = tf.constant([[3, 3, 5, 5]],
dtype=tf.float32)
boxes2 = tf.constant([[3, 3, 5, 5]],
dtype=tf.float32)
giou = ops.giou(boxes1, boxes2)
self.assertEqual(giou.dtype, tf.float32)
return giou
giou = self.execute(graph_fn, [])
self.assertAllClose(expected_giou_tensor, giou)
def test_giou_with_zero_area_boxes(self):
expected_giou_tensor = [0]
def graph_fn():
boxes1 = tf.constant([[1, 1, 1, 1]],
dtype=tf.float32) dtype=tf.float32)
boxes2 = tf.constant([[3, 3, 5, 5], [1, 1, 1, 1]], boxes2 = tf.constant([[1, 1, 1, 1]],
dtype=tf.float32) dtype=tf.float32)
giou = ops.giou(boxes1, boxes2) giou = ops.giou(boxes1, boxes2)
...@@ -1672,7 +1707,7 @@ class TestGIoU(test_case.TestCase): ...@@ -1672,7 +1707,7 @@ class TestGIoU(test_case.TestCase):
giou = self.execute(graph_fn, []) giou = self.execute(graph_fn, [])
self.assertAllClose(expected_giou_tensor, giou) self.assertAllClose(expected_giou_tensor, giou)
def test_giou_l1_same(self): def test_giou_correlates_with_same_l1(self):
expected_giou_tensor = [ expected_giou_tensor = [
2/3, 3/5 2/3, 3/5
] ]
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment