gd = tf.gradients(target, target_vars)
gds = [tf.square(tf.norm(_gd, ord=2)) for _gd in gd if _gd is not None]
r = tf.add_n(gds)
self.d_loss = self.d_lambda * tf.reduce_mean(r)
self.gan.add_metric("gp", self.d_loss)
def losses(self):
After Change
if "components" in self.config:
target_vars = []
for component in self.config.components:
c = getattr(gan, component)
target_vars += c.variables()
else:
target_vars = v.variables()
gd = tf.gradients(target, target_vars)
gds = [tf.square(_gd) for _gd in gd if _gd is not None]
self.loss = tf.add_n([self.d_lambda * tf.reduce_mean(_r) for _r in gds])
self.gds = gds
self.gd = gd
self.target_vars = target_vars
self.target = target