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
e3f09134
"tools/python/vscode:/vscode.git/clone" did not exist on "63d963cadd8bfc9f88f4d7e1ef28ab1e28e0cef0"
Commit
e3f09134
authored
Sep 09, 2021
by
Vishnu Banna
Browse files
head update
parent
350b0aa6
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
3 deletions
+28
-3
official/vision/beta/projects/yolo/modeling/heads/yolo_head.py
...ial/vision/beta/projects/yolo/modeling/heads/yolo_head.py
+28
-3
No files found.
official/vision/beta/projects/yolo/modeling/heads/yolo_head.py
View file @
e3f09134
...
@@ -30,10 +30,11 @@ class YoloHead(tf.keras.layers.Layer):
...
@@ -30,10 +30,11 @@ class YoloHead(tf.keras.layers.Layer):
output_extras
=
0
,
output_extras
=
0
,
norm_momentum
=
0.99
,
norm_momentum
=
0.99
,
norm_epsilon
=
0.001
,
norm_epsilon
=
0.001
,
kernel_initializer
=
'
glorot_uniform
'
,
kernel_initializer
=
'
VarianceScaling
'
,
kernel_regularizer
=
None
,
kernel_regularizer
=
None
,
bias_regularizer
=
None
,
bias_regularizer
=
None
,
activation
=
None
,
activation
=
None
,
smart_bias
=
False
,
**
kwargs
):
**
kwargs
):
"""Yolo Prediction Head initialization function.
"""Yolo Prediction Head initialization function.
...
@@ -68,6 +69,7 @@ class YoloHead(tf.keras.layers.Layer):
...
@@ -68,6 +69,7 @@ class YoloHead(tf.keras.layers.Layer):
self
.
_output_extras
=
output_extras
self
.
_output_extras
=
output_extras
self
.
_output_conv
=
(
classes
+
output_extras
+
5
)
*
boxes_per_level
self
.
_output_conv
=
(
classes
+
output_extras
+
5
)
*
boxes_per_level
self
.
_smart_bias
=
smart_bias
self
.
_base_config
=
dict
(
self
.
_base_config
=
dict
(
activation
=
activation
,
activation
=
activation
,
...
@@ -85,10 +87,29 @@ class YoloHead(tf.keras.layers.Layer):
...
@@ -85,10 +87,29 @@ class YoloHead(tf.keras.layers.Layer):
use_bn
=
False
,
use_bn
=
False
,
**
self
.
_base_config
)
**
self
.
_base_config
)
def
bias_init
(
self
,
scale
,
inshape
,
isize
=
640
,
no_per_conf
=
8
):
def
bias
(
shape
,
dtype
):
init
=
tf
.
keras
.
initializers
.
Zeros
()
base
=
init
(
shape
,
dtype
=
dtype
)
if
self
.
_smart_bias
:
base
=
tf
.
reshape
(
base
,
[
self
.
_boxes_per_level
,
-
1
])
box
,
conf
,
classes
=
tf
.
split
(
base
,
[
4
,
1
,
-
1
],
axis
=-
1
)
conf
+=
tf
.
math
.
log
(
no_per_conf
/
((
isize
/
scale
)
**
2
))
classes
+=
tf
.
math
.
log
(
0.6
/
(
self
.
_classes
-
0.99
))
base
=
tf
.
concat
([
box
,
conf
,
classes
],
axis
=-
1
)
base
=
tf
.
reshape
(
base
,
[
-
1
])
return
base
return
bias
def
build
(
self
,
input_shape
):
def
build
(
self
,
input_shape
):
self
.
_head
=
dict
()
self
.
_head
=
dict
()
for
key
in
self
.
_key_list
:
for
key
in
self
.
_key_list
:
self
.
_head
[
key
]
=
nn_blocks
.
ConvBN
(
**
self
.
_conv_config
)
scale
=
2
**
int
(
key
)
self
.
_head
[
key
]
=
nn_blocks
.
ConvBN
(
bias_initializer
=
self
.
bias_init
(
scale
,
input_shape
[
key
][
-
1
]),
**
self
.
_conv_config
)
def
call
(
self
,
inputs
):
def
call
(
self
,
inputs
):
outputs
=
dict
()
outputs
=
dict
()
...
@@ -104,9 +125,13 @@ class YoloHead(tf.keras.layers.Layer):
...
@@ -104,9 +125,13 @@ class YoloHead(tf.keras.layers.Layer):
def
num_boxes
(
self
):
def
num_boxes
(
self
):
if
self
.
_min_level
is
None
or
self
.
_max_level
is
None
:
if
self
.
_min_level
is
None
or
self
.
_max_level
is
None
:
raise
Exception
(
raise
Exception
(
'
M
odel has to be built before number of boxes can be determined
.
'
)
'
m
odel has to be built before number of boxes can be determined'
)
return
(
self
.
_max_level
-
self
.
_min_level
+
1
)
*
self
.
_boxes_per_level
return
(
self
.
_max_level
-
self
.
_min_level
+
1
)
*
self
.
_boxes_per_level
@
property
def
num_heads
(
self
):
return
(
self
.
_max_level
-
self
.
_min_level
+
1
)
def
get_config
(
self
):
def
get_config
(
self
):
config
=
dict
(
config
=
dict
(
min_level
=
self
.
_min_level
,
min_level
=
self
.
_min_level
,
...
...
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