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
4a09d217
Commit
4a09d217
authored
May 13, 2021
by
Fan Yang
Committed by
A. Unique TensorFlower
May 13, 2021
Browse files
Internal change.
PiperOrigin-RevId: 373725548
parent
e04d2efc
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
5 additions
and
2 deletions
+5
-2
official/core/base_trainer.py
official/core/base_trainer.py
+2
-1
official/modeling/optimization/ema_optimizer.py
official/modeling/optimization/ema_optimizer.py
+3
-1
No files found.
official/core/base_trainer.py
View file @
4a09d217
...
...
@@ -210,7 +210,8 @@ class Trainer(_AsyncTrainer):
self
.
_runtime_options
=
get_runtime_options
(
config
)
# Creates a shadow copy of the weights to store weights moving average.
if
isinstance
(
self
.
_optimizer
,
optimization
.
ExponentialMovingAverage
):
if
isinstance
(
self
.
_optimizer
,
optimization
.
ExponentialMovingAverage
)
and
not
self
.
_optimizer
.
has_shadow_copy
:
self
.
_optimizer
.
shadow_copy
(
self
.
_model
)
# global_step increases by 1 after each training iteration.
...
...
official/modeling/optimization/ema_optimizer.py
View file @
4a09d217
...
...
@@ -76,6 +76,8 @@ class ExponentialMovingAverage(tf.keras.optimizers.Optimizer):
self
.
_dynamic_decay
=
dynamic_decay
self
.
_optimizer
=
optimizer
self
.
_track_trackable
(
self
.
_optimizer
,
'base_optimizer'
)
self
.
_average_weights
=
None
self
.
_model_weights
=
None
def
shadow_copy
(
self
,
model
:
tf
.
keras
.
Model
):
"""Creates shadow variables for the given model weights."""
...
...
@@ -89,7 +91,7 @@ class ExponentialMovingAverage(tf.keras.optimizers.Optimizer):
@
property
def
has_shadow_copy
(
self
):
"""Whether this optimizer has created shadow variables."""
return
self
.
_model_weights
is
not
None
return
self
.
_model_weights
is
not
None
and
self
.
_average_weights
is
not
None
def
_create_slots
(
self
,
var_list
):
self
.
_optimizer
.
_create_slots
(
var_list
=
var_list
)
# pylint: disable=protected-access
...
...
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