“max_poolig2d_3/MaxPool”的1减去2导致维度大小为负

2024-10-08 16:48:34 发布

您现在位置:Python中文网/ 问答频道 /正文

我是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}$

我在添加了所有的池层之后得到了这个错误。在

你知道怎么解决吗?在


Tags: alphasizelayerstfmaxsameinputspool
1条回答
网友
1楼 · 发布于 2024-10-08 16:48:34

Cov2d_3层(x3)的激活/输出尺寸为(?)?,1512年)。pool3无法处理此1x1输出。因此,错误增加了。在

你应该输入更大的图像。或者相应地调整conv和pool层的内核。在

使用此选项可以估计conv和pool层的输出大小:

If padding == "SAME": output_spatial_shape[i] = ceil(input_spatial_shape[i] / strides[i])

If padding == "VALID": output_spatial_shape[i] = ceil((input_spatial_shape[i] - (spatial_filter_shape[i]-1) * dilation_rate[i]) / strides[i]).

确保输出具有足够好的大小,并且最终输出大小是所需的大小。在

我希望这有帮助!在

相关问题 更多 >

    热门问题