Cropping2D
类tf_keras.layers.Cropping2D(cropping=((0, 0), (0, 0)), data_format=None, **kwargs)
用于二维输入(例如图片)的裁剪层。
它沿空间维度(即高度和宽度)进行裁剪。
示例
>>> input_shape = (2, 28, 28, 3)
>>> x = np.arange(np.prod(input_shape)).reshape(input_shape)
>>> y = tf.keras.layers.Cropping2D(cropping=((2, 2), (4, 4)))(x)
>>> print(y.shape)
(2, 24, 20, 3)
参数
(对称高度裁剪, 对称宽度裁剪)
。((顶部裁剪, 底部裁剪), (左侧裁剪, 右侧裁剪))
channels_last
(默认)或 channels_first
之一。输入中维度的顺序。channels_last
对应于形状为 (batch_size, height, width, channels)
的输入,而 channels_first
对应于形状为 (batch_size, channels, height, width)
的输入。如果未指定,则使用 TF-Keras 配置文件 ~/.keras/keras.json
(如果存在)中找到的 image_data_format
值,否则为 'channels_last'。默认为 'channels_last'。输入形状
4D 张量,形状为:- 如果 data_format
为 "channels_last"
:(batch_size, rows, cols, channels)
- 如果 data_format
为 "channels_first"
:(batch_size, channels, rows, cols)
输出形状
4D 张量,形状为:- 如果 data_format
为 "channels_last"
:(batch_size, cropped_rows, cropped_cols, channels)
- 如果 data_format
为 "channels_first"
:(batch_size, channels, cropped_rows, cropped_cols)