Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
seminar-breakout
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Shashank Suhas
seminar-breakout
Commits
08a5cf6f
Commit
08a5cf6f
authored
Jul 28, 2017
by
Yuxin Wu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix regularize collection for replicated mode
parent
2ecdbc00
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
5 additions
and
0 deletions
+5
-0
tensorpack/models/regularize.py
tensorpack/models/regularize.py
+5
-0
No files found.
tensorpack/models/regularize.py
View file @
08a5cf6f
...
@@ -61,14 +61,19 @@ def regularize_cost(regex, func, name='regularize_cost'):
...
@@ -61,14 +61,19 @@ def regularize_cost(regex, func, name='regularize_cost'):
def
regularize_cost_from_collection
(
name
=
'regularize_cost'
):
def
regularize_cost_from_collection
(
name
=
'regularize_cost'
):
"""
"""
Get the cost from the regularizers in ``tf.GraphKeys.REGULARIZATION_LOSSES``.
Get the cost from the regularizers in ``tf.GraphKeys.REGULARIZATION_LOSSES``.
In replicated mode, will only regularize variables within the current tower.
Returns:
Returns:
a scalar tensor, the regularization loss.
a scalar tensor, the regularization loss.
"""
"""
regularization_losses
=
set
(
tf
.
get_collection
(
tf
.
GraphKeys
.
REGULARIZATION_LOSSES
))
regularization_losses
=
set
(
tf
.
get_collection
(
tf
.
GraphKeys
.
REGULARIZATION_LOSSES
))
ctx
=
get_current_tower_context
()
if
len
(
regularization_losses
)
>
0
:
if
len
(
regularization_losses
)
>
0
:
# NOTE: this collection doesn't grow with towers.
# NOTE: this collection doesn't grow with towers.
# It is only added with variables that are newly created.
# It is only added with variables that are newly created.
if
ctx
.
has_own_variables
:
# be careful of the first tower (name='')
regularization_losses
=
ctx
.
filter_vars_by_vs_name
(
regularization_losses
)
print
([
k
.
name
for
k
in
regularization_losses
])
logger
.
info
(
"Add REGULARIZATION_LOSSES of {} tensors on the total cost."
.
format
(
len
(
regularization_losses
)))
logger
.
info
(
"Add REGULARIZATION_LOSSES of {} tensors on the total cost."
.
format
(
len
(
regularization_losses
)))
reg_loss
=
tf
.
add_n
(
list
(
regularization_losses
),
name
=
name
)
reg_loss
=
tf
.
add_n
(
list
(
regularization_losses
),
name
=
name
)
return
reg_loss
return
reg_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