-2

下面的代码只需要 32*32 的输入,我想输入 128*128 的图像,如何去做。代码来自教程 - https://github.com/awjuliani/TF-Tutorials/blob/master/DCGAN.ipynb

定义生成器(z):

zP = slim.fully_connected(z,4*4*256,normalizer_fn=slim.batch_norm,\
    activation_fn=tf.nn.relu,scope='g_project',weights_initializer=initializer)
zCon = tf.reshape(zP,[-1,4,4,256])

gen1 = slim.convolution2d_transpose(\
    zCon,num_outputs=64,kernel_size=[5,5],stride=[2,2],\
    padding="SAME",normalizer_fn=slim.batch_norm,\
    activation_fn=tf.nn.relu,scope='g_conv1', weights_initializer=initializer)

gen2 = slim.convolution2d_transpose(\
    gen1,num_outputs=32,kernel_size=[5,5],stride=[2,2],\
    padding="SAME",normalizer_fn=slim.batch_norm,\
    activation_fn=tf.nn.relu,scope='g_conv2', weights_initializer=initializer)

gen3 = slim.convolution2d_transpose(\
    gen2,num_outputs=16,kernel_size=[5,5],stride=[2,2],\
    padding="SAME",normalizer_fn=slim.batch_norm,\
    activation_fn=tf.nn.relu,scope='g_conv3', weights_initializer=initializer)

g_out = slim.convolution2d_transpose(\
    gen3,num_outputs=1,kernel_size=[32,32],padding="SAME",\
    biases_initializer=None,activation_fn=tf.nn.tanh,\
    scope='g_out', weights_initializer=initializer)

return g_out

def鉴别器(底部,重用=假):

dis1 = slim.convolution2d(bottom,16,[4,4],stride=[2,2],padding="SAME",\
    biases_initializer=None,activation_fn=lrelu,\
    reuse=reuse,scope='d_conv1',weights_initializer=initializer)

dis2 = slim.convolution2d(dis1,32,[4,4],stride=[2,2],padding="SAME",\
    normalizer_fn=slim.batch_norm,activation_fn=lrelu,\
    reuse=reuse,scope='d_conv2', weights_initializer=initializer)

dis3 = slim.convolution2d(dis2,64,[4,4],stride=[2,2],padding="SAME",\
    normalizer_fn=slim.batch_norm,activation_fn=lrelu,\
    reuse=reuse,scope='d_conv3',weights_initializer=initializer)

d_out = slim.fully_connected(slim.flatten(dis3),1,activation_fn=tf.nn.sigmoid,\
    reuse=reuse,scope='d_out', weights_initializer=initializer)

return d_out

以下是我输入 128*128 图像时出现的错误。

 Trying to share variable d_out/weights, but specified shape (1024, 1) and found shape (16384, 1).
4

1 回答 1

0

生成器正在生成 32*32 的图像,因此当我们在鉴别器中输入任何其他维度时,它会导致给定的错误。

解决方案是从生成器生成 128*128 的图像,乘以 1。添加更多 no。层数(在这种情况下为 2) 2. 更改生成器的输入

zP = slim.fully_connected(z,16*16*256,normalizer_fn=slim.batch_norm,\
activation_fn=tf.nn.relu,scope='g_project',weights_initializer=initializer)
zCon = tf.reshape(zP,[-1,16,16,256])
于 2017-09-08T17:12:02.687 回答