| 21 | |
| 22 | |
| 23 | class 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 | |
| 50 | class ClipCallback(Callback): |
no outgoing calls
no test coverage detected
searching dependent graphs…