目前我编写了一个 GAN 来生成 MNIST 数字,但生成器不想工作。首先,我选择每批形状为 100 的 z,放入一个图层以形成形状 (7,7, 256)。然后将 conv2d_transpose 层转换为 28、28、1。(这基本上是一个 mnist pic)
我有两个问题 1.) 这段代码不明显。你有什么线索,为什么?2.) 我非常了解转置卷积的工作原理,但我找不到任何资源来计算给定输入、步幅和特定于 Tensorflow 的内核大小的输出大小。我找到的有用信息是https://arxiv.org/pdf/1603.07285v1.pdf,但是 Tensorflow 中的填充例如非常不同。你能帮助我吗?
mb_size = 32 #Size of image batch to apply at each iteration.
X_dim = 784
z_dim = 100
h_dim = 7*7*256
dropoutRate = 0.7
alplr = 0.2 #leaky Relu
def generator(z, G_W1, G_b1, keepProb, first_shape):
G_W1 = tf.Variable(xavier_init([z_dim, h_dim]))
G_b1 = tf.Variable(tf.zeros(shape=[h_dim]))
G_h1 = lrelu(tf.matmul(z, G_W1) + G_b1, alplr)
G_h1Drop = tf.nn.dropout(G_h1, keepProb) # drop out
X = tf.reshape(G_h1Drop, shape=first_shape)
out = create_new_trans_conv_layer(X, 256, INPUT_CHANNEL, [3, 3], [2,2], "transconv1", [-1, 28, 28, 1])
return out
# new transposed cnn
def create_new_trans_conv_layer(input_data, num_input_channels, num_output_channels, filter_shape, stripe, name, output_shape):
# setup the filter input shape for tf.nn.conv_2d
conv_filt_shape = [filter_shape[0], filter_shape[1], num_output_channels, num_input_channels]
# initialise weights and bias for the filter
weights = tf.Variable(tf.truncated_normal(conv_filt_shape, stddev=0.03),
name=name + '_W')
bias = tf.Variable(tf.truncated_normal([num_input_channels]), name=name + '_b')
# setup the convolutional layer operation
conv1 = tf.nn.conv2d_transpose(input_data, weights, output_shape, [1, stripe[0], stripe[1], 1], padding='SAME')
# add the bias
conv1 += bias
# apply a ReLU non-linear activation
conv1 = lrelu(conv1, alplr)
return conv1
...
_, G_loss_curr = sess.run(
[G_solver, G_loss],
feed_dict={z: sample_z(mb_size, z_dim), keepProb: 1.0} #training generator