tf.keras.layers.GlobalMaxPooling2D

2D全局最大池化

输入张量维度为[batch, height, width, channel],输出张量维度为[batch,  channel]

keras.layers.GlobalMaxPooling2D(data_format=None)

data_format: 表示输入张量的维度顺序,默认为 [batch, height, width, channel]


示例

from tensorflow.keras.layers import GlobalMaxPooling2D
import tensorflow as tf
import numpy as np

# 定义一个全局最大池化层
pool = GlobalMaxPooling2D()

# 生成一个维度为[64, 720, 720, 3]的矩阵
x = np.random.random((64, 720, 720, 3))

# 转成tensor类型,第一个维度64表示batch
# numpy中的数据类型和tensorflow中的数据类型完全兼容,所以这一步可以省略
x = tf.convert_to_tensor(x)
print(x.shape) # [64, 720, 720, 3]

# 进行全局最大池化
y = pool(x)
print(y.shape) # [64, 3]

猜你喜欢

转载自blog.csdn.net/weixin_46566663/article/details/127621823