[译] TF-api(1) tf.nn.max_pool

tf.nn.max_pool

Args:

value: A 4-D Tensor with shape [batch, height, width, channels] and type tf.float32.

value是一个4D的tensor,是我们对其进行maxpooling的对象,它的shape是[batch, height, width, channels]

ksize: A list of ints that has length >= 4. The size of the window for each dimension of the input tensor.

ksize表示对于输入的tensor的每一维的池化尺度,比如在height那一维是2的话,表示在height轴会以2作为池化尺度。因为往往不会对batch和channel作池化,所以值一般为1。即ksize=[1, kheight, kwidth, 1]

strides: A list of ints that has length >= 4. The stride of the sliding window for each dimension of the input tensor.

strides表示步长, 意同conv2d里面的strides,每一维度都表示窗口的在对应维度上的滑动步长。

padding: A string, either 'VALID' or 'SAME'. The padding algorithm. See the @{tf.nn.convolution$comment here}

padding表示pooling的模式,意同conv2d里面的strides。SAME模式就是将滑动窗口与矩阵进行左对齐,然后向右滑动。一直滑到与矩阵最右边那一列不相交为止。

data_format: A string. ‘NHWC’ and ‘NCHW’ are supported.

数据格式,这个一般都是默认的,不需要改变,具体是什么作用暂时不清楚。

name: Optional name for the operation.

op名字

Returns: A Tensor with type tf.float32. The max pooled output tensor.


举例:

import tensorflow as tf
import numpy as np

data = np.random.randint(1, 9, size=[1, 5, 5, 1])
print(np.transpose(data, (0, 3, 1, 2)))
input_ = tf.convert_to_tensor(data, dtype=tf.float32)
res = tf.nn.max_pool(input_, ksize=[1, 2, 2, 1], strides=[1, 1, 1, 1],padding='SAME')

with tf.Session() as sess:
    tf.global_variables_initializer().run()
    output = sess.run(res, feed_dict={input_: data})
    output = np.array(output)
    print(np.transpose(output, (0, 3, 1, 2)))
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值