tf.keras.layers.MaxPool2D——tf2.1 Document

参考自tf2.1官方文档:
https://www.tensorflow.org/api_docs/python/tf/keras/layers/MaxPool2D


Max pooling operation for spatial data.
对空间数据进行 Max pooling 操作

tf.keras.layers.MaxPool2D(
    pool_size=(2, 2), strides=None, padding='valid', data_format=None, **kwargs
)




Arguments:

  • pool_size: integer or tuple of 2 integers, factors by which to downscale (vertical, horizontal).
    (2, 2) will halve the input in both spatial dimension.
    If only one integer is specified, the same window length will be used for both dimensions.

  • pool_size: 一个整数或者二元元组,用于指定pooling kernel的大小。
    默认为(2, 2),会使输入在两个维度上减半。
    如果只传入一个整数,kernel(window)长度在两个维度上相等(就是window的长宽相等)。

  • strides: Integer, tuple of 2 integers, or None. Strides values. If None, it will default to pool_size.

  • strides: 一个整数或者二元元组或者None,指定步长值。如果为None,它将被指定为pool_size

  • padding: One of “valid” or “same” (case-insensitive).

  • padding: “valid” 或者 “same”(不区分大小写)

  • 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, height, width, channels) while channels_first corresponds to inputs with shape (batch, channels, height, width).
    It defaults to the image_data_format value found in your Keras config file at ~/.keras/keras.json.
    If you never set it, then it will be “channels_last”.

  • data_format: 字符串,'channels_last' (default)或channels_first
    指定输入维度的次序。
    'channels_last' 指定输入的形状为(batch, height, width, channels)
    channels_first指定输入的形状为(batch, channels, height, width)
    其默认设置在配置文件~/.keras/keras.json中的image_data_format
    若在该文件中没有设置,则将为'channels_last'




Input shape:

  • If data_format=‘channels_last’: 4D tensor with shape (batch_size, rows, cols, channels).
  • 如果 data_format=‘channels_last’,则输入4D张量shape为(batch_size, rows, cols, channels)
  • If data_format=‘channels_first’: 4D tensor with shape (batch_size, channels, rows, cols).
  • 如果 data_format=‘channels_first’,则输入4D张量shape为(batch_size, channels, rows, cols)




Output shape:

  • If data_format=‘channels_last’: 4D tensor with shape (batch_size, pooled_rows, pooled_cols, channels).
  • 如果 data_format=‘channels_last’,则输出4D张量shape为(batch_size, pooled_rows, pooled_cols, channels)
  • If data_format=‘channels_first’: 4D tensor with shape (batch_size, channels, pooled_rows, pooled_cols).
  • 如果 data_format=‘channels_first’,则输出4D张量shape为(batch_size, channels, pooled_rows, pooled_cols, )
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
tf.keras.layers.MaxPool2DTensorFlow 中的一个层,用于在 2D 输入数据上执行最大池化操作。最大池化是一种常用的下采样操作,它在输入数据的局部区域中选择最大值作为输出。 这个层通常用于卷积神经网络(CNN)中,以减少图像数据的空间维度,并提取最显著的特征。最大池化层可以帮助模型更好地捕捉图像中的纹理、形状和边缘等重要信息。 MaxPool2D 层的常用参数包括: - pool_size: 池化窗口的大小,通常为一个整数或一个长度为2的整数元组。例如,(2, 2) 表示池化窗口为 2x2 的大小。 - strides: 池化窗口在每个维度上的步幅大小。通常为一个整数或一个长度为2的整数元组。默认情况下,步幅与池化窗口大小相同。 - padding: 填充方式,可选值为 'valid'(不填充)或 'same'(填充使输出与输入具有相同的空间维度)。 下面是一个示例代码,展示如何在 TensorFlow 中使用 MaxPool2D 层: ```python import tensorflow as tf model = tf.keras.Sequential([ # 输入数据的形状为 (batch_size, height, width, channels) tf.keras.layers.Conv2D(filters=32, kernel_size=(3, 3), activation='relu', input_shape=(28, 28, 1)), tf.keras.layers.MaxPool2D(pool_size=(2, 2)), # 更多的卷积层和池化层可以继续添加 tf.keras.layers.Flatten(), tf.keras.layers.Dense(units=64, activation='relu'), tf.keras.layers.Dense(units=10, activation='softmax') ]) # 编译模型并进行训练等操作... ``` 上述代码中,首先使用了一个卷积层(Conv2D)来提取图像特征,然后使用 MaxPool2D 层进行最大池化操作,之后可以继续添加更多的卷积层和池化层。最后,通过 Flatten 层将多维数据展平为一维数据,并连接全连接层(Dense)进行分类。 希望以上解答对您有帮助!如果有更多问题,请随时提问。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值