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
e741d7b4
Commit
e741d7b4
authored
Jul 29, 2017
by
Yuxin Wu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update WGAN to include two possible ways of clipping
parent
321440af
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
5 deletions
+24
-5
examples/GAN/WGAN.py
examples/GAN/WGAN.py
+24
-5
No files found.
examples/GAN/WGAN.py
View file @
e741d7b4
...
@@ -36,15 +36,34 @@ class Model(DCGAN.Model):
...
@@ -36,15 +36,34 @@ class Model(DCGAN.Model):
def
_get_optimizer
(
self
):
def
_get_optimizer
(
self
):
lr
=
symbolic_functions
.
get_scalar_var
(
'learning_rate'
,
1e-4
,
summary
=
True
)
lr
=
symbolic_functions
.
get_scalar_var
(
'learning_rate'
,
1e-4
,
summary
=
True
)
opt
=
tf
.
train
.
RMSPropOptimizer
(
lr
)
opt
=
tf
.
train
.
RMSPropOptimizer
(
lr
)
return
opt
# add clipping to D optimizer
# An alternative way to implement the clipping:
def
clip
(
p
):
"""
n
=
p
.
op
.
name
def clip(v):
n = v.op.name
if not n.startswith('discrim/'):
if not n.startswith('discrim/'):
return None
return None
logger.info("Clip {}".format(n))
logger.info("Clip {}".format(n))
return
tf
.
clip_by_value
(
p
,
-
0.01
,
0.01
)
return tf.clip_by_value(
v
, -0.01, 0.01)
return optimizer.VariableAssignmentOptimizer(opt, clip)
return optimizer.VariableAssignmentOptimizer(opt, clip)
"""
class
ClipCallback
(
Callback
):
def
_setup_graph
(
self
):
vars
=
tf
.
trainable_variables
()
ops
=
[]
for
v
in
vars
:
n
=
v
.
op
.
name
if
not
n
.
startswith
(
'discrim/'
):
continue
logger
.
info
(
"Clip {}"
.
format
(
n
))
ops
.
append
(
tf
.
assign
(
v
,
tf
.
clip_by_value
(
v
,
-
0.01
,
0.01
)))
self
.
_op
=
tf
.
group
(
*
ops
,
name
=
'clip'
)
def
_trigger_step
(
self
):
self
.
_op
.
run
()
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
...
@@ -58,7 +77,7 @@ if __name__ == '__main__':
...
@@ -58,7 +77,7 @@ if __name__ == '__main__':
config
=
TrainConfig
(
config
=
TrainConfig
(
model
=
Model
(),
model
=
Model
(),
dataflow
=
DCGAN
.
get_data
(
args
.
data
),
dataflow
=
DCGAN
.
get_data
(
args
.
data
),
callbacks
=
[
ModelSaver
()],
callbacks
=
[
ModelSaver
()
,
ClipCallback
()
],
steps_per_epoch
=
500
,
steps_per_epoch
=
500
,
max_epoch
=
200
,
max_epoch
=
200
,
session_init
=
SaverRestore
(
args
.
load
)
if
args
.
load
else
None
session_init
=
SaverRestore
(
args
.
load
)
if
args
.
load
else
None
...
...
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