Example #1
0
    def gaussian_MLP_encoder(self, x, n_hidden=256, reuse=False):
        with tf.variable_scope("gaussian_MLP_encoder", reuse=reuse):
            output = tf.reshape(x, [-1, 28, 28, 1])

            output = tf.layers.conv2d(output, 128, 5)
            output = utils.LeakyReLU(output)

            output = tf.layers.conv2d(output, 32, 5)
            output = utils.LeakyReLU(output)

            output = tf.layers.conv2d(output, 16, 5)
            output = utils.LeakyReLU(output)

            output = tf.reshape(output, [-1, 4096])
            output = tf.layers.dense(output, 256)

            output = utils.LeakyReLU(output)
            gaussian_params = tf.layers.dense(output,
                                              2 * self.get_latent_dim())

            # The mean parameter is unconstrained
            mean = gaussian_params[:, :self.get_latent_dim()]
            stddev = 1e-6 + tf.nn.softplus(
                gaussian_params[:, self.get_latent_dim():])
            z = mean + stddev * tf.random_normal(
                tf.shape(mean), 0, 1, dtype=tf.float32)

        return mean, stddev, z
Example #2
0
    def build_discriminator(self, inputs, reuse=False):
        n_hidden = 256
        with tf.variable_scope("Discriminator", reuse=reuse) as vs:
            # Hidden fully connected layer with 256 neurons
            layer_1 = tf.layers.dense(inputs, n_hidden)
            layer_1 = utils.LeakyReLU(layer_1, alpha=0.01)

            layer_2 = tf.layers.dense(layer_1, n_hidden)
            layer_2 = utils.LeakyReLU(layer_2, alpha=0.01)

            output = tf.layers.dense(layer_2, 1)

        variables = tf.contrib.framework.get_variables(vs)
        return tf.reshape(output, [-1])
Example #3
0
    def build_generator(self, z, reuse=False):
        with tf.variable_scope('Generator', reuse=reuse) as vs:
            output = tf.layers.dense(z, 6 * 6 * self.get_latent_dim())
            output = utils.LeakyReLU(output)

            output = tf.reshape(output, [-1, 6, 6, self.get_latent_dim()])

            output = tf.layers.conv2d_transpose(output, 64, 4, strides=2)
            output = utils.LeakyReLU(output)

            output = tf.layers.conv2d_transpose(output, 1, 2, strides=2)
            output = tf.nn.sigmoid(output)

        variables = tf.contrib.framework.get_variables(vs)
        return tf.reshape(output, [-1, self.get_image_dim()]), variables
Example #4
0
    def build_discriminator(self, x, reuse=False):
        with tf.variable_scope('Dummy', reuse=reuse) as vs:
            output = tf.reshape(x, [-1, 64, 64, 3])

            output = tf.layers.conv2d(output, 128, 4, strides=2)
            output = utils.LeakyReLU(output)

            output = tf.layers.conv2d(output, 32, 3, strides=2)
            output = utils.LeakyReLU(output)

            output = tf.layers.conv2d(output, 16, 2, strides=1)
            output = utils.LeakyReLU(output)

            output = tf.reshape(output, [-1, 3136])
            output = tf.layers.dense(output, 256)

            output = utils.LeakyReLU(output)
            output = tf.layers.dense(output, 1)

        return tf.reshape(output, [-1])
Example #5
0
    def build_discriminator(self, x, reuse=False):
        with tf.variable_scope('Discriminator', reuse=reuse) as vs:
            output = tf.reshape(x, [-1, 28, 28, 1])

            output = tf.layers.conv2d(output, 128, 5)
            output = utils.LeakyReLU(output)

            output = tf.layers.conv2d(output, 32, 5)
            output = utils.LeakyReLU(output)

            output = tf.layers.conv2d(output, 16, 5)
            output = utils.LeakyReLU(output)

            output = tf.reshape(output, [-1, 4096])
            output = tf.layers.dense(output, 256)

            output = utils.LeakyReLU(output)
            output = tf.layers.dense(output, 1)

        variables = tf.contrib.framework.get_variables(vs)
        return tf.reshape(output, [-1])