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
3feb41c9
Commit
3feb41c9
authored
Jul 22, 2022
by
A. Unique TensorFlower
Browse files
Internal change
PiperOrigin-RevId: 462680315
parent
b8234e65
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
13 deletions
+9
-13
official/projects/yt8m/modeling/yt8m_model.py
official/projects/yt8m/modeling/yt8m_model.py
+7
-11
official/projects/yt8m/modeling/yt8m_model_test.py
official/projects/yt8m/modeling/yt8m_model_test.py
+2
-2
No files found.
official/projects/yt8m/modeling/yt8m_model.py
View file @
3feb41c9
...
@@ -65,12 +65,11 @@ class DbofModel(tf.keras.Model):
...
@@ -65,12 +65,11 @@ class DbofModel(tf.keras.Model):
norm_epsilon: A `float` added to variance to avoid dividing by zero.
norm_epsilon: A `float` added to variance to avoid dividing by zero.
**kwargs: keyword arguments to be passed.
**kwargs: keyword arguments to be passed.
"""
"""
del
num_frames
self
.
_self_setattr_tracking
=
False
self
.
_self_setattr_tracking
=
False
self
.
_config_dict
=
{
self
.
_config_dict
=
{
"input_specs"
:
input_specs
,
"input_specs"
:
input_specs
,
"num_classes"
:
num_classes
,
"num_classes"
:
num_classes
,
"num_frames"
:
num_frames
,
"params"
:
params
"params"
:
params
}
}
self
.
_num_classes
=
num_classes
self
.
_num_classes
=
num_classes
...
@@ -80,26 +79,23 @@ class DbofModel(tf.keras.Model):
...
@@ -80,26 +79,23 @@ class DbofModel(tf.keras.Model):
self
.
_norm
=
layers
.
experimental
.
SyncBatchNormalization
self
.
_norm
=
layers
.
experimental
.
SyncBatchNormalization
else
:
else
:
self
.
_norm
=
layers
.
BatchNormalization
self
.
_norm
=
layers
.
BatchNormalization
if
tf
.
keras
.
backend
.
image_data_format
()
==
"channels_last"
:
bn_axis
=
-
1
else
:
bn_axis
=
1
bn_axis
=
-
1
# [batch_size x num_frames x num_features]
# [batch_size x num_frames x num_features]
feature_size
=
input_specs
.
shape
[
-
1
]
feature_size
=
input_specs
.
shape
[
-
1
]
# shape 'excluding' batch_size
# shape 'excluding' batch_size
model_input
=
tf
.
keras
.
Input
(
shape
=
self
.
_input_specs
.
shape
[
1
:])
model_input
=
tf
.
keras
.
Input
(
shape
=
self
.
_input_specs
.
shape
[
1
:])
reshaped_input
=
tf
.
reshape
(
model_input
,
[
-
1
,
feature_size
])
tf
.
summary
.
histogram
(
"input_hist"
,
model_input
)
tf
.
summary
.
histogram
(
"input_hist"
,
model_input
)
input_data
=
model_input
# configure model
# configure model
if
params
.
add_batch_norm
:
if
params
.
add_batch_norm
:
reshaped_
input
=
self
.
_norm
(
input
_data
=
self
.
_norm
(
axis
=
bn_axis
,
axis
=
bn_axis
,
momentum
=
norm_momentum
,
momentum
=
norm_momentum
,
epsilon
=
norm_epsilon
,
epsilon
=
norm_epsilon
,
name
=
"input_bn"
)(
name
=
"input_bn"
)(
reshaped_
input
)
input
_data
)
# activation = reshaped input * cluster weights
# activation = reshaped input * cluster weights
if
params
.
cluster_size
>
0
:
if
params
.
cluster_size
>
0
:
...
@@ -108,7 +104,7 @@ class DbofModel(tf.keras.Model):
...
@@ -108,7 +104,7 @@ class DbofModel(tf.keras.Model):
kernel_regularizer
=
kernel_regularizer
,
kernel_regularizer
=
kernel_regularizer
,
kernel_initializer
=
tf
.
random_normal_initializer
(
kernel_initializer
=
tf
.
random_normal_initializer
(
stddev
=
1
/
tf
.
sqrt
(
tf
.
cast
(
feature_size
,
tf
.
float32
))))(
stddev
=
1
/
tf
.
sqrt
(
tf
.
cast
(
feature_size
,
tf
.
float32
))))(
reshaped_
input
)
input
_data
)
if
params
.
add_batch_norm
:
if
params
.
add_batch_norm
:
activation
=
self
.
_norm
(
activation
=
self
.
_norm
(
...
@@ -142,7 +138,7 @@ class DbofModel(tf.keras.Model):
...
@@ -142,7 +138,7 @@ class DbofModel(tf.keras.Model):
pooling_method
=
pooling_method
,
pooling_method
=
pooling_method
,
hidden_layer_size
=
params
.
context_gate_cluster_bottleneck_size
,
hidden_layer_size
=
params
.
context_gate_cluster_bottleneck_size
,
kernel_regularizer
=
kernel_regularizer
)
kernel_regularizer
=
kernel_regularizer
)
activation
=
tf
.
reshape
(
activation
,
[
-
1
,
num_frames
,
params
.
cluster_size
])
activation
=
utils
.
frame_pooling
(
activation
,
params
.
pooling_method
)
activation
=
utils
.
frame_pooling
(
activation
,
params
.
pooling_method
)
# activation = activation * hidden1_weights
# activation = activation * hidden1_weights
...
...
official/projects/yt8m/modeling/yt8m_model_test.py
View file @
3feb41c9
...
@@ -34,7 +34,7 @@ class YT8MNetworkTest(parameterized.TestCase, tf.test.TestCase):
...
@@ -34,7 +34,7 @@ class YT8MNetworkTest(parameterized.TestCase, tf.test.TestCase):
num_frames: number of frames.
num_frames: number of frames.
feature_dims: indicates total dimension size of the features.
feature_dims: indicates total dimension size of the features.
"""
"""
input_specs
=
tf
.
keras
.
layers
.
InputSpec
(
shape
=
[
num_frames
,
feature_dims
])
input_specs
=
tf
.
keras
.
layers
.
InputSpec
(
shape
=
[
None
,
None
,
feature_dims
])
num_classes
=
3862
num_classes
=
3862
model
=
yt8m_model
.
DbofModel
(
model
=
yt8m_model
.
DbofModel
(
...
@@ -44,7 +44,7 @@ class YT8MNetworkTest(parameterized.TestCase, tf.test.TestCase):
...
@@ -44,7 +44,7 @@ class YT8MNetworkTest(parameterized.TestCase, tf.test.TestCase):
input_specs
=
input_specs
)
input_specs
=
input_specs
)
# batch = 2 -> arbitrary value for test
# batch = 2 -> arbitrary value for test
inputs
=
np
.
random
.
rand
(
2
*
num_frames
,
feature_dims
)
inputs
=
np
.
random
.
rand
(
2
,
num_frames
,
feature_dims
)
logits
=
model
(
inputs
)
logits
=
model
(
inputs
)
self
.
assertAllEqual
([
2
,
num_classes
],
logits
.
numpy
().
shape
)
self
.
assertAllEqual
([
2
,
num_classes
],
logits
.
numpy
().
shape
)
...
...
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