解讀MaxPooling1D和GlobalMaxPooling1D的區(qū)別
MaxPooling1D和GlobalMaxPooling1D區(qū)別
import tensorflow as tf
from tensorflow import keras
input_shape = (2, 3, 4)
x = tf.random.normal(input_shape)
print(x)
y=keras.layers.GlobalMaxPool1D()(x)
print("*"*20)
print(y)
'''
"""Global average pooling operation for temporal data.
Examples:
>>> input_shape = (2, 3, 4)
>>> x = tf.random.normal(input_shape)
>>> y = tf.keras.layers.GlobalAveragePooling1D()(x)
>>> print(y.shape)
(2, 4)
Arguments:
data_format: A string,
one of `channels_last` (default) or `channels_first`.
The ordering of the dimensions in the inputs.
`channels_last` corresponds to inputs with shape
`(batch, steps, features)` while `channels_first`
corresponds to inputs with shape
`(batch, features, steps)`.
Call arguments:
inputs: A 3D tensor.
mask: Binary tensor of shape `(batch_size, steps)` indicating whether
a given step should be masked (excluded from the average).
Input shape:
- If `data_format='channels_last'`:
3D tensor with shape:
`(batch_size, steps, features)`
- If `data_format='channels_first'`:
3D tensor with shape:
`(batch_size, features, steps)`
Output shape:
2D tensor with shape `(batch_size, features)`.
"""
'''
print("--"*20)
input_shape = (2, 3, 4)
x = tf.random.normal(input_shape)
print(x)
y=keras.layers.MaxPool1D(pool_size=2,strides=1)(x) # strides 不指定 默認(rèn)等于 pool_size
print("*"*20)
print(y)
輸出如下圖
上圖GlobalMaxPool1D 相當(dāng)于給每一個(gè)樣本每列的最大值

而MaxPool1D就是普通的對(duì)每一個(gè)樣本進(jìn)行一個(gè)窗口(1D是一維列窗口)滑動(dòng)取最大值。
tf.keras.layers.GlobalMaxPool1D()
與tf.keras.layers.Conv1D的輸入一樣,輸入一個(gè)三維數(shù)據(jù)(batch_size,feature_size,output_dimension)
x = tf.constant([[1., 2., 3.], [4., 5., 6.]]) ???????x = tf.reshape(x, [2, 3, 1]) max_pool_1d=tf.keras.layers.GlobalMaxPooling1D() max_pool_1d(x)
其中max_pool_1d(x)和tf.math.reduce_max(x,axis=-2,keepdims=False)作用相同
總結(jié)
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
Tensorflow 2.4 搭建單層和多層 Bi-LSTM 模型
這篇文章主要為大家介紹了Tensorflow 2.4 搭建單層 Bi-LSTM 模型和多層 Bi-LSTM 模型的實(shí)現(xiàn)過(guò)程詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-01-01
詳解Python中的內(nèi)建函數(shù),可迭代對(duì)象,迭代器
這篇文章主要介紹了Python內(nèi)建函數(shù),可迭代對(duì)象,迭代器,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-04-04
解決Atom安裝Hydrogen無(wú)法運(yùn)行python3的問(wèn)題
今天小編就為大家分享一篇解決Atom安裝Hydrogen無(wú)法運(yùn)行python3的問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2019-08-08
python3+PyQt5實(shí)現(xiàn)自定義流體混合窗口部件
這篇文章主要為大家詳細(xì)介紹了python3+PyQt5實(shí)現(xiàn)自定義流體混合窗口部件,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-04-04
python機(jī)器學(xué)習(xí)庫(kù)xgboost的使用
這篇文章主要介紹了python機(jī)器學(xué)習(xí)庫(kù)xgboost的使用,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-01-01
django實(shí)現(xiàn)前后臺(tái)交互實(shí)例
本篇文章主要介紹了django實(shí)現(xiàn)前后臺(tái)交互實(shí)例,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-08-08
Python函數(shù)any()和all()的用法及區(qū)別介紹
any函數(shù):any(x),只要x中有一個(gè)不為空,0,false就返回True,否則返回False。all(x)函數(shù)必須x中的所有元素均不為空,0,false才會(huì)返回True,否則返回False。接下來(lái)通過(guò)本文給大家介紹Python函數(shù)any()和all()的用法及區(qū)別介紹,需要的朋友參考下吧2018-09-09
python實(shí)現(xiàn)從字典中刪除元素的方法
這篇文章主要介紹了python實(shí)現(xiàn)從字典中刪除元素的方法,涉及Python中del方法的使用技巧,非常具有實(shí)用價(jià)值,需要的朋友可以參考下2015-05-05

