解读MaxPooling1D和GlobalMaxPooling1D的区别
作者:zhangztSky 时间:2023-07-21 10:54:43
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
标签:MaxPooling1D,GlobalMaxPooling1D
0
投稿
猜你喜欢
python flask开发的简单基金查询工具
2023-10-29 21:35:42
使用pyshp包进行shapefile文件修改的例子
2023-07-01 08:28:35
python3中TQDM库安装及使用详解
2023-02-17 20:05:55
利用Python 实现图片转字符画
2022-05-06 11:31:01
利用CSS改善网站可访问性
2010-10-20 20:12:00
提升Python运行速度的5个小技巧
2021-07-28 20:25:24
Oracle常用命令大全集
2010-07-21 13:18:00
python进程管理工具supervisor的安装与使用教程
2023-10-15 20:41:57
python matplotlib坐标轴设置的方法
2022-03-26 03:44:04
Python爬虫分析微博热搜关键词的实现代码
2022-11-29 16:13:44
python调用c++ ctype list传数组或者返回数组的方法
2021-09-28 01:24:04
Python爬虫之网络请求
2023-10-29 21:28:08
php使用curl抓取qq空间的访客信息示例
2023-10-30 05:50:32
有关缓存 Cache 的随想
2008-06-09 14:25:00
Python制作动态词频条形图的全过程
2021-04-25 11:14:52
Linux mysql安装修改root密码服务
2010-10-14 13:59:00
使用Python OpenCV为CNN增加图像样本的实现
2023-10-13 02:51:31
python读取Kafka实例
2023-10-22 17:22:58
Golang回调函数与闭包和接口函数的定义及使用介绍
2024-04-26 17:27:22
Python三元运算实现方法
2021-12-27 06:02:52