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
fb2b278d
Commit
fb2b278d
authored
Jun 03, 2021
by
Vishnu Banna
Browse files
nms ops used by detection generator
parent
0352c8f4
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
804 additions
and
209 deletions
+804
-209
official/vision/beta/projects/yolo/ops/box_ops.py
official/vision/beta/projects/yolo/ops/box_ops.py
+246
-207
official/vision/beta/projects/yolo/ops/box_ops_test.py
official/vision/beta/projects/yolo/ops/box_ops_test.py
+0
-2
official/vision/beta/projects/yolo/ops/math_ops.py
official/vision/beta/projects/yolo/ops/math_ops.py
+67
-0
official/vision/beta/projects/yolo/ops/nms_ops.py
official/vision/beta/projects/yolo/ops/nms_ops.py
+491
-0
No files found.
official/vision/beta/projects/yolo/ops/box_ops.py
View file @
fb2b278d
This diff is collapsed.
Click to expand it.
official/vision/beta/projects/yolo/ops/box_ops_test.py
View file @
fb2b278d
...
@@ -27,10 +27,8 @@ class InputUtilsTest(parameterized.TestCase, tf.test.TestCase):
...
@@ -27,10 +27,8 @@ class InputUtilsTest(parameterized.TestCase, tf.test.TestCase):
expected_shape
=
np
.
array
([
num_boxes
,
4
])
expected_shape
=
np
.
array
([
num_boxes
,
4
])
xywh_box
=
box_ops
.
yxyx_to_xcycwh
(
boxes
)
xywh_box
=
box_ops
.
yxyx_to_xcycwh
(
boxes
)
yxyx_box
=
box_ops
.
xcycwh_to_yxyx
(
boxes
)
yxyx_box
=
box_ops
.
xcycwh_to_yxyx
(
boxes
)
xyxy_box
=
box_ops
.
xcycwh_to_xyxy
(
boxes
)
self
.
assertAllEqual
(
tf
.
shape
(
xywh_box
).
numpy
(),
expected_shape
)
self
.
assertAllEqual
(
tf
.
shape
(
xywh_box
).
numpy
(),
expected_shape
)
self
.
assertAllEqual
(
tf
.
shape
(
yxyx_box
).
numpy
(),
expected_shape
)
self
.
assertAllEqual
(
tf
.
shape
(
yxyx_box
).
numpy
(),
expected_shape
)
self
.
assertAllEqual
(
tf
.
shape
(
xyxy_box
).
numpy
(),
expected_shape
)
@
parameterized
.
parameters
((
1
),
(
5
),
(
7
))
@
parameterized
.
parameters
((
1
),
(
5
),
(
7
))
def
test_ious
(
self
,
num_boxes
):
def
test_ious
(
self
,
num_boxes
):
...
...
official/vision/beta/projects/yolo/ops/math_ops.py
0 → 100755
View file @
fb2b278d
"""A set of private math operations used to safely implement the yolo loss"""
import
tensorflow
as
tf
import
tensorflow.keras.backend
as
K
def
rm_nan_inf
(
x
,
val
=
0.0
):
"""remove nan and infinity
Args:
x: any `Tensor` of any type.
val: value to replace nan and infinity with.
Return:
a `Tensor` with nan and infinity removed.
"""
cond
=
tf
.
math
.
logical_or
(
tf
.
math
.
is_nan
(
x
),
tf
.
math
.
is_inf
(
x
))
val
=
tf
.
cast
(
val
,
dtype
=
x
.
dtype
)
x
=
tf
.
where
(
cond
,
val
,
x
)
return
x
def
rm_nan
(
x
,
val
=
0.0
):
"""remove nan and infinity.
Args:
x: any `Tensor` of any type.
val: value to replace nan.
Return:
a `Tensor` with nan removed.
"""
cond
=
tf
.
math
.
is_nan
(
x
)
val
=
tf
.
cast
(
val
,
dtype
=
x
.
dtype
)
x
=
tf
.
where
(
cond
,
val
,
x
)
return
x
def
divide_no_nan
(
a
,
b
):
"""Nan safe divide operation built to allow model compilation in tflite.
Args:
a: any `Tensor` of any type.
b: any `Tensor` of any type with the same shape as tensor a.
Return:
a `Tensor` representing a divided by b, with all nan values removed.
"""
zero
=
tf
.
cast
(
0.0
,
b
.
dtype
)
return
tf
.
where
(
b
==
zero
,
zero
,
a
/
b
)
def
mul_no_nan
(
x
,
y
):
"""Nan safe multiply operation built to allow model compilation in tflite and
to allowing one tensor to mask another. Where ever x is zero the
multiplication is not computed and the value is replaced with a zero. This is
requred because 0 * nan = nan. This can make computation unstable in some
cases where the intended behavior is for zero to mean ignore.
Args:
x: any `Tensor` of any type.
y: any `Tensor` of any type with the same shape as tensor x.
Return:
a `Tensor` representing x times y, where x is used to safely mask the
tensor y.
"""
return
tf
.
where
(
x
==
0
,
tf
.
cast
(
0
,
x
.
dtype
),
x
*
y
)
official/vision/beta/projects/yolo/ops/nms_ops.py
0 → 100755
View file @
fb2b278d
This diff is collapsed.
Click to expand it.
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