Keras 3 API 文档 / 层 API / 重塑层 / Cropping2D层

Cropping2D层

[source]

Cropping2D class

keras.layers.Cropping2D(cropping=((0, 0), (0, 0)), data_format=None, **kwargs)

裁剪层用于2D输入(例如图片).

它沿着空间维度进行裁剪,即高度和宽度.

示例:

>>> input_shape = (2, 28, 28, 3)
>>> x = np.arange(np.prod(input_shape)).reshape(input_shape)
>>> y = keras.layers.Cropping2D(cropping=((2, 2), (4, 4)))(x)
>>> y.shape
(2, 24, 20, 3)

参数: cropping: 整数,或2个整数的元组,或2个2个整数的元组. - 如果为整数: 对高度和宽度应用相同的对称裁剪. - 如果为2个整数的元组: 解释为高度和宽度的两个不同的对称裁剪值: (对称高度裁剪, 对称宽度裁剪). - 如果为2个2个整数的元组: 解释为 ((顶部裁剪, 底部裁剪), (左侧裁剪, 右侧裁剪)). data_format: 字符串,取值为"channels_last"(默认)或 "channels_first".输入中维度的顺序. "channels_last"对应输入形状 (batch_size, height, width, channels),而"channels_first" 对应输入形状 (batch_size, channels, height, width). 如果未指定,使用在您的Keras配置文件~/.keras/keras.json中找到的image_data_format值(如果存在).默认为 "channels_last".

输入形状: 4D张量,形状为: - 如果data_format"channels_last": (batch_size, height, width, channels) - 如果data_format"channels_first": (batch_size, channels, height, width)

输出形状: 4D张量,形状为: - 如果data_format"channels_last": (batch_size, cropped_height, cropped_width, channels) - 如果data_format"channels_first": (batch_size, channels, cropped_height, cropped_width)