第一階段-入門詳細圖文講解tensorflow1.4 API-tf.nn.max_pool

這裏寫圖片描述

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.]]]]
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章