Example #1
0
    def train(self, logger, sess, batch_xs, epoch_idx, batch_idx, batch_total,
              log_flag, keep_prob):
        random_z = get_random_normal(batch_xs.shape[0], self.z_dim)

        for i in range(5):
            _, dis_loss_val = sess.run([self.dis_solver, self.dis_loss],
                                       feed_dict={
                                           self.X: batch_xs,
                                           self.keep_prob: keep_prob,
                                           self.z: random_z
                                       })
        _, dec_loss_val = sess.run([self.dec_solver, self.dec_loss],
                                   feed_dict={
                                       self.X: batch_xs,
                                       self.keep_prob: keep_prob,
                                       self.z: random_z
                                   })
        _, enc_loss_val = sess.run([self.enc_solver, self.enc_loss],
                                   feed_dict={
                                       self.X: batch_xs,
                                       self.keep_prob: keep_prob
                                   })

        total_loss_val = dis_loss_val + dec_loss_val + enc_loss_val
        if log_flag == True:
            logger.debug(
                'Epoch %.3i, Batch[%.3i/%i], Dis loss : %.4E, Dec loss : %.4E, Enc loss : %.4E, Train loss: %.4E'
                % (epoch_idx, batch_idx + 1, batch_total, dis_loss_val,
                   dec_loss_val, enc_loss_val, total_loss_val))

        return total_loss_val
Example #2
0
    def inference_with_output(self, logger, sess, batch_xs, epoch_idx, batch_idx, batch_total, log_flag, keep_prob):
        random_z = get_random_normal(batch_xs.shape[0], self.z_dim)

        dis_loss_val, dec_loss_val, output_val = sess.run([self.dis_loss, self.dec_loss, self.output], feed_dict={self.X: batch_xs, self.keep_prob: keep_prob, self.z: random_z})

        total_loss_val = dis_loss_val + dec_loss_val
        if log_flag == True:
            logger.debug('Epoch %.3i, Batch[%.3i/%i], Dis loss : %.4E, Dec loss : %.4E, Test loss: %.4E' % (epoch_idx, batch_idx + 1, batch_total, dis_loss_val, dec_loss_val, total_loss_val))

        return total_loss_val, output_val