我是Python和Tensorflow的新手,现在我正在学习DC-GAN。我实现了这个版本的鉴别器:
def discriminator(images, reuse=False, alpha=0.2):
with tf.variable_scope('discriminator', reuse=reuse):
x1 = tf.layers.conv2d(images, 128, 5, strides=2, padding='same')
pool1 = tf.layers.max_pooling2d(inputs=x1, pool_size=[2, 2], strides=2)
relu1 = tf.maximum(alpha * pool1, pool1)
x2 = tf.layers.conv2d(relu1, 256, 5, strides=2, padding='same')
pool2 = tf.layers.max_pooling2d(inputs=x2, pool_size=[2, 2], strides=2)
bn2 = tf.layers.batch_normalization(pool2, training=True)
relu2 = tf.maximum(alpha * bn2, bn2)
x3 = tf.layers.conv2d(relu2, 512, 5, strides=2, padding='same')
pool3 = tf.layers.max_pooling2d(inputs=x3, pool_size=[2, 2], strides=2)
bn3 = tf.layers.batch_normalization(pool3, training=True)
relu3 = tf.maximum(alpha * bn3, bn3)
x4 = tf.layers.conv2d(relu2, 512, 5, strides=2, padding='same')
pool4 = tf.layers.max_pooling2d(inputs=x4, pool_size=[2, 2], strides=2)
bn4 = tf.layers.batch_normalization(pool4, training=True)
relu4 = tf.maximum(alpha * bn4, bn4)
flat = tf.reshape(relu3, (-1, 4*4*256))
logits = tf.layers.dense(flat, 1)
out = tf.sigmoid(logits)
return out, logits
但是当我试着运行它时,我得到了一个错误:
^{pr2}$我在添加了所有的池层之后得到了这个错误。在
你知道怎么解决吗?在
Cov2d_3层(x3)的激活/输出尺寸为(?)?,1512年)。pool3无法处理此1x1输出。因此,错误增加了。在
你应该输入更大的图像。或者相应地调整conv和pool层的内核。在
使用此选项可以估计conv和pool层的输出大小:
确保输出具有足够好的大小,并且最终输出大小是所需的大小。在
我希望这有帮助!在
相关问题 更多 >
编程相关推荐