【问题标题】:What is output tensor of Max Pooling 2D Layer in TensorFlow?TensorFlow 中 Max Pooling 2D 层的输出张量是多少?
【发布时间】:2017-09-13 04:52:19
【问题描述】:

我试图了解一些有关 tensorflow 的基础知识 我在阅读最大池化 2D 层的文档时被卡住了:https://www.tensorflow.org/tutorials/layers#pooling_layer_1

这是如何指定 max_pooling2d 的:

pool1 = tf.layers.max_pooling2d(inputs=conv1, pool_size=[2, 2], strides=2)

其中conv1 有一个形状为[batch_size, image_width, image_height, channels] 的张量,具体在本例中为[batch_size, 28, 28, 32]

所以我们的输入是一个形状为:[batch_size, 28, 28, 32] 的张量。

我对最大池化 2D 层的理解是,它将应用大小为 pool_size(在本例中为 2x2)的过滤器,并将滑动窗口移动stride(也是 2x2)。这意味着图像的widthheight 都将减半,即我们最终将得到每个通道 14x14 像素(总共 32 个通道),这意味着我们的输出是一个形状为:[batch_size, 14, 14, 32] 的张量。

但是根据上面的链接,输出张量的形状是[batch_size, 14, 14, 1]

Our output tensor produced by max_pooling2d() (pool1) has a shape of 
[batch_size, 14, 14, 1]: the 2x2 filter reduces width and height by 50%.

我在这里错过了什么?

32 是如何转换为 1 的?

他们稍后在这里应用相同的逻辑:https://www.tensorflow.org/tutorials/layers#convolutional_layer_2_and_pooling_layer_2

但这次是正确的,即[batch_size, 14, 14, 64]变成[batch_size, 7, 7, 64](频道数相同)。

【问题讨论】:

    标签: python tensorflow max-pooling


    【解决方案1】:

    是的,使用 strides=2x2 的 2x2 max pool 会将数据减少一半,并且输出深度不会改变。这是我给定的测试代码,输出形状是(14, 14, 32),可能有问题?

    #!/usr/bin/env python
    
    import tensorflow as tf
    from tensorflow.examples.tutorials.mnist import input_data
    
    mnist = input_data.read_data_sets('./MNIST_data/', one_hot=True)
    
    conv1 = tf.placeholder(tf.float32, [None,28,28,32])
    pool1 = tf.layers.max_pooling2d(inputs=conv1, pool_size=[2,2], strides=2)
    print pool1.get_shape()
    

    输出是:

    Extracting ./MNIST_data/train-images-idx3-ubyte.gz
    Extracting ./MNIST_data/train-labels-idx1-ubyte.gz
    Extracting ./MNIST_data/t10k-images-idx3-ubyte.gz
    Extracting ./MNIST_data/t10k-labels-idx1-ubyte.gz
    (?, 14, 14, 32)
    

    【讨论】:

    • 感谢您的回答。我想文档是错误的,即有错字?
    【解决方案2】:

    Nikola,如你所想,已更正。

    学习卷积和池化的概念,我遇到了这个线程。感谢您的问题,这将我带到了内容丰富的文档。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-15
      • 1970-01-01
      • 2019-08-06
      • 2016-11-29
      相关资源
      最近更新 更多