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)
参数
(symmetric_height_crop, symmetric_width_crop)。((top_crop, bottom_crop), (left_crop, right_crop))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)