(self)
Define the cost functions.
Define the cost functions.
Define the cost functions .
def _create_loss_optimizer(self):
        """Define the cost functions."""
        # Define two discriminator losses, based on the fake and real
        # discriminator predictions.
        self.loss_d_real = tf.reduce_mean(
            tf.nn.sigmoid_cross_entropy_with_logits(
                labels=tf.ones_like(self.D1), logits=self.D1))
        self.loss_d_fake = tf.reduce_mean(
            tf.nn.sigmoid_cross_entropy_with_logits(
                labels=tf.zeros_like(self.D2), logits=self.D2))

        # Define the loss for the discriminator and generator networks.
        self.loss_d = tf.add(self.loss_d_real, self.loss_d_fake)
        self.loss_g = tf.reduce_mean(
            tf.nn.sigmoid_cross_entropy_with_logits(
                labels=tf.ones_like(self.D2), logits=self.D2))

        t_vars = tf.trainable_variables()
        if self.d_pretrain:
            self.d_pre_vars = [var for var in t_vars
                               if var.name.startswith('D_pre/')]
        self.d_vars = [var for var in t_vars if var.name.startswith('D/')]
        self.g_vars = [var for var in t_vars if var.name.startswith('G/')]

        # Define optimizers for the discriminator and generator networks.
        opt_d = tf.train.AdamOptimizer(self.d_learning_rate, beta1=0.5)
        opt_g = tf.train.AdamOptimizer(self.g_learning_rate, beta1=0.5)
        self.opt_d = opt_d.minimize(self.loss_d, var_list=self.d_vars)
        self.opt_g = opt_g.minimize(self.loss_g, var_list=self.g_vars)
def _create_loss_optimizer ( self ) : # Define two discriminator losses, based on the fake and real # discriminator predictions. self . loss_d_real = tf . reduce_mean ( tf . nn . sigmoid_cross_entropy_with_logits ( labels = tf . ones_like ( self . D1 ) , logits = self . D1 ) ) self . loss_d_fake = tf . reduce_mean ( tf . nn . sigmoid_cross_entropy_with_logits ( labels = tf . zeros_like ( self . D2 ) , logits = self . D2 ) ) # Define the loss for the discriminator and generator networks. self . loss_d = tf . add ( self . loss_d_real , self . loss_d_fake ) self . loss_g = tf . reduce_mean ( tf . nn . sigmoid_cross_entropy_with_logits ( labels = tf . ones_like ( self . D2 ) , logits = self . D2 ) ) t_vars = tf . trainable_variables ( ) if self . d_pretrain : self . d_pre_vars = [ var for var in t_vars if var . name . startswith ( 'D_pre/' ) ] self . d_vars = [ var for var in t_vars if var . name . startswith ( 'D/' ) ] self . g_vars = [ var for var in t_vars if var . name . startswith ( 'G/' ) ] # Define optimizers for the discriminator and generator networks. opt_d = tf . train . AdamOptimizer ( self . d_learning_rate , beta1 = 0.5 ) opt_g = tf . train . AdamOptimizer ( self . g_learning_rate , beta1 = 0.5 ) self . opt_d = opt_d . minimize ( self . loss_d , var_list = self . d_vars ) self . opt_g = opt_g . minimize ( self . loss_g , var_list = self . g_vars )