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
c33d3ef4
"torchvision/git@developer.sourcefind.cn:OpenDAS/vision.git" did not exist on "09ce6758ad6ab3177f3fdec3b1bb7c7033b16712"
Unverified
Commit
c33d3ef4
authored
Apr 17, 2019
by
Haoyu Zhang
Committed by
GitHub
Apr 17, 2019
Browse files
Update logic to rescale L2 loss in distribution strategy (#6601)
parent
2ae6d37a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
2 additions
and
4 deletions
+2
-4
official/resnet/resnet_run_loop.py
official/resnet/resnet_run_loop.py
+2
-4
No files found.
official/resnet/resnet_run_loop.py
View file @
c33d3ef4
...
@@ -419,16 +419,14 @@ def resnet_model_fn(features, labels, mode, model_class,
...
@@ -419,16 +419,14 @@ def resnet_model_fn(features, labels, mode, model_class,
return
'batch_normalization'
not
in
name
return
'batch_normalization'
not
in
name
loss_filter_fn
=
loss_filter_fn
or
exclude_batch_norm
loss_filter_fn
=
loss_filter_fn
or
exclude_batch_norm
# Add weight decay to the loss. We need to scale the regularization loss
# Add weight decay to the loss.
# manually as losses other than in tf.losses and tf.keras.losses don't scale
# automatically.
l2_loss
=
weight_decay
*
tf
.
add_n
(
l2_loss
=
weight_decay
*
tf
.
add_n
(
# loss is computed using fp32 for numerical stability.
# loss is computed using fp32 for numerical stability.
[
[
tf
.
nn
.
l2_loss
(
tf
.
cast
(
v
,
tf
.
float32
))
tf
.
nn
.
l2_loss
(
tf
.
cast
(
v
,
tf
.
float32
))
for
v
in
tf
.
compat
.
v1
.
trainable_variables
()
for
v
in
tf
.
compat
.
v1
.
trainable_variables
()
if
loss_filter_fn
(
v
.
name
)
if
loss_filter_fn
(
v
.
name
)
])
/
tf
.
distribute
.
get_strategy
().
num_replicas_in_sync
])
tf
.
compat
.
v1
.
summary
.
scalar
(
'l2_loss'
,
l2_loss
)
tf
.
compat
.
v1
.
summary
.
scalar
(
'l2_loss'
,
l2_loss
)
loss
=
cross_entropy
+
l2_loss
loss
=
cross_entropy
+
l2_loss
...
...
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