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
2a1af832
Commit
2a1af832
authored
Jul 30, 2017
by
Yuxin Wu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
only freeze trainable variables (fix #351)
parent
2d5b44e6
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
2 deletions
+7
-2
tensorpack/tfutils/varreplace.py
tensorpack/tfutils/varreplace.py
+7
-2
No files found.
tensorpack/tfutils/varreplace.py
View file @
2a1af832
...
...
@@ -51,7 +51,7 @@ def remap_variables(fn):
def
freeze_variables
():
"""
Return a context, where all variables (reused or not) returned by
Return a context, where all
trainable
variables (reused or not) returned by
``get_variable`` will have no gradients (they will be wrapped by ``tf.stop_gradient``).
But they will still be in ``TRAINABLE_VARIABLES`` collections so they will get
saved correctly. This is useful to fix certain variables for fine-tuning.
...
...
@@ -62,7 +62,12 @@ def freeze_variables():
with varreplace.freeze_variable():
x = FullyConnected('fc', x, 1000) # fc/* will not be trained
"""
return
remap_variables
(
lambda
v
:
tf
.
stop_gradient
(
v
))
def
custom_getter
(
getter
,
*
args
,
**
kwargs
):
v
=
getter
(
*
args
,
**
kwargs
)
if
kwargs
.
pop
(
'trainable'
,
True
):
v
=
tf
.
stop_gradient
(
v
)
return
v
return
custom_getter_scope
(
custom_getter
)
@
deprecated
(
"Renamed to remap_variables"
,
"2017-11-06"
)
...
...
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