MCPcopy Index your code
hub / github.com/tensorpack/tensorpack / Model

Class Model

examples/GAN/WGAN.py:23–47  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

21
22
23class Model(DCGAN.Model):
24 # def generator(self, z):
25 # you can override generator to remove BatchNorm, it will still work in WGAN
26
27 def build_losses(self, vecpos, vecneg):
28 # the Wasserstein-GAN losses
29 self.d_loss = tf.reduce_mean(vecneg - vecpos, name='d_loss')
30 self.g_loss = tf.negative(tf.reduce_mean(vecneg), name='g_loss')
31 add_moving_summary(self.d_loss, self.g_loss)
32
33 def optimizer(self):
34 opt = tf.train.RMSPropOptimizer(1e-4)
35 return opt
36
37 # An alternative way to implement the clipping:
38 """
39 from tensorpack.tfutils import optimizer
40 def clip(v):
41 n = v.op.name
42 if not n.startswith('discrim/'):
43 return None
44 logger.info("Clip {}".format(n))
45 return tf.clip_by_value(v, -0.01, 0.01)
46 return optimizer.VariableAssignmentOptimizer(opt, clip)
47 """
48
49
50class ClipCallback(Callback):

Callers 1

WGAN.pyFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…