網站首頁 編程語言 正文
MaxPooling1D和GlobalMaxPooling1D區別
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 不指定 默認等于 pool_size
print("*"*20)
print(y)
輸出如下圖
上圖GlobalMaxPool1D 相當于給每一個樣本每列的最大值
而MaxPool1D就是普通的對每一個樣本進行一個窗口(1D是一維列窗口)滑動取最大值。
tf.keras.layers.GlobalMaxPool1D()
與tf.keras.layers.Conv1D的輸入一樣,輸入一個三維數據(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)作用相同
總結
原文鏈接:https://blog.csdn.net/qq_38574975/article/details/111468756
相關推薦
- 2023-01-11 Android網絡訪問之Retrofit使用教程_Android
- 2022-11-09 Android?使用maven?publish插件發布產物(aar)流程實踐_Android
- 2022-12-12 Kotlin構造函數與成員變量和init代碼塊執行順序詳細講解_Android
- 2024-04-02 Centos無法獲取IP報No suitable device found for this con
- 2022-01-30 uniapp history路由配置,apache服務器簡單配置(刷新報404解決方法)
- 2022-11-18 Python實現常見數據格式轉換的方法詳解_python
- 2021-12-04 使用Go實現TLS服務器和客戶端的示例_Golang
- 2022-04-24 教你使用mongoose實現多集合關聯查詢_MongoDB
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支