第一阶段-入门详细图文讲解tensorflow1.4 API-tf.nn.max_pool

来源:互联网 发布:看黄子片哪个软件安全 编辑:程序博客网 时间:2024/05/17 14:27

这里写图片描述

max_pool(
value,#一个4维张量,由data_format指定
ksize,#一维整型张量,是一个窗口尺寸,由输入张量每一维决定
strides,#一维张量,表示分割窗口的步长,由输入张量每一维决定
padding,#边缘填充方式
data_format=’NHWC’,#数据格式的顺序
name=None#操作的名称
)

max_pool:做最大池化操作。操作很简单,类似于conv2D操作格式。这样解释,还是比较抽象。

看一个例子。

# -*- coding: utf-8 -*-"""Created on Mon Dec 18 09:38:40 2017@author: suncl"""import tensorflow as tf  scalar=tf.constant([ 1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,8.0,7.0,6.0,5.0,4.0,3.0,2.0,1.0 ])  tensor=tf.reshape(scalar,[1,4,4,1])  pooling=tf.nn.max_pool(tensor,[1,2,2,1],[1,1,1,1],padding='VALID')  with tf.Session() as sess:      print(sess.run(tensor))      print("-----max_pool result------")      result=sess.run(pooling)      print (result)  

运行结果:

[[[[ 1.]   [ 2.]   [ 3.]   [ 4.]]  [[ 5.]   [ 6.]   [ 7.]   [ 8.]]  [[ 8.]   [ 7.]   [ 6.]   [ 5.]]  [[ 4.]   [ 3.]   [ 2.]   [ 1.]]]]-----max_pool result------[[[[ 6.]   [ 7.]   [ 8.]]  [[ 8.]   [ 7.]   [ 8.]]  [[ 8.]   [ 7.]   [ 6.]]]]
阅读全文
0 0
原创粉丝点击