人脸生成TensorFlow的大小从28px增加conv2d_transpose

时间:2019-02-19 09:18:41

标签: python-3.x tensorflow tensorflow-datasets generative-adversarial-network

我正在关注After I refresh it shows in plain text,并可以使用我的GPU成功生成28px大小的面孔。但是我不知道如何使用下面的生成器函数的逻辑来增加面部的大小(当前为28px):

def generator(z, out_channel_dim, is_train=True, alpha=0.2, keep_prob=0.5):
    with tf.variable_scope('generator', reuse=(not is_train)):
        # First fully connected layer, 4x4x1024
        fc = tf.layers.dense(z, 4 * 4 * 1024, use_bias=False)
        fc = tf.reshape(fc, (-1, 4, 4, 1024))
        bn0 = tf.layers.batch_normalization(fc, training=is_train)
        lrelu0 = tf.maximum(alpha * bn0, bn0)
        drop0 = tf.layers.dropout(lrelu0, keep_prob, training=is_train)

        # Deconvolution, 7x7x512
        conv1 = tf.layers.conv2d_transpose(drop0, 512, 4, 1, 'valid', use_bias=False)
        bn1 = tf.layers.batch_normalization(conv1, training=is_train)
        lrelu1 = tf.maximum(alpha * bn1, bn1)
        drop1 = tf.layers.dropout(lrelu1, keep_prob, training=is_train)

        # Deconvolution, 14x14x256
        conv2 = tf.layers.conv2d_transpose(drop1, 256, 5, 2, 'same', use_bias=False)
        bn2 = tf.layers.batch_normalization(conv2, training=is_train)
        lrelu2 = tf.maximum(alpha * bn2, bn2)
        drop2 = tf.layers.dropout(lrelu2, keep_prob, training=is_train)

        # Output layer, 28x28xn
        logits = tf.layers.conv2d_transpose(drop2, out_channel_dim, 5, 2, 'same')

        out = tf.tanh(logits)

        return out

我认为我需要更改以下内容:

conv2 = tf.layers.conv2d_transpose(drop1, 256, 5, 2, 'same', use_bias=False)

1 个答案:

答案 0 :(得分:0)

应该在最后一层logits上进行更改,因为那是确定输出大小的层。将out_channel_dim的值更改为所需的大小将是解决方案。这可能会导致一些错误(由于内核大小和步幅值)或结果将不同(因为您的网络没有经过此大小的训练)。