Cropping2D
類別tf_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 = 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)