def domain_classifier(self, images, name="G", reuse=False):
random_uniform_init = tf.random_uniform_initializer(minval=-0.1, maxval=0.1)
with tf.variable_scope(name):
tf.get_variable_scope().reuse_variables()
with tf.variable_scope("images"):
# "generator/images"
images_W = tf.get_variable("images_W", [self.img_dims, self.G_hidden_size], "float32", random_uniform_init)
images_emb = tf.matmul(images, images_W) # B,H
l2_loss = tf.constant(0.0)
with tf.variable_scope("domain"):
if reuse:
tf.get_variable_scope().reuse_variables()
with tf.variable_scope("output"):
output_W = tf.get_variable("output_W", [self.G_hidden_size, self.num_domains],
"float32", random_uniform_init)
output_b = tf.get_variable("output_b", [self.num_domains], "float32", random_uniform_init)
l2_loss += tf.nn.l2_loss(output_W)
l2_loss += tf.nn.l2_loss(output_b)
logits = tf.nn.xw_plus_b(images_emb, output_W, output_b, name="logits")
predictions = tf.argmax(logits, 1, name="predictions")
return predictions, logits, l2_loss
评论列表
文章目录