Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ModelZoo
ResNet50_tensorflow
Commits
cabd4d16
Commit
cabd4d16
authored
Aug 06, 2020
by
Kaushik Shivakumar
Browse files
clean up and improve tests
parent
e0e440e1
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
50 additions
and
15 deletions
+50
-15
research/object_detection/core/box_list_ops.py
research/object_detection/core/box_list_ops.py
+2
-2
research/object_detection/core/box_list_ops_test.py
research/object_detection/core/box_list_ops_test.py
+2
-2
research/object_detection/utils/ops_test.py
research/object_detection/utils/ops_test.py
+46
-11
No files found.
research/object_detection/core/box_list_ops.py
View file @
cabd4d16
...
@@ -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.
...
...
research/object_detection/core/box_list_ops_test.py
View file @
cabd4d16
...
@@ -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
)
...
...
research/object_detection/utils/ops_test.py
View file @
cabd4d16
...
@@ -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_case
s
(
self
):
def
test_giou_
with_overlap
s
(
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
)
dtype
=
tf
.
float32
)
boxes2
=
tf
.
constant
([[
3
,
3
,
5
,
5
],
[
1
,
1
,
1
,
1
]],
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
)
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
]
]
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment