GAN 更改输入大小会导致错误



下面的代码只需要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 鉴别器(bottom, reuse=False(:

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).

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

解决方案是从生成器生成 128*128 张图像,通过 1. 添加更多编号。层数(本例中为 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])

相关内容

  • 没有找到相关文章

最新更新