Keras 3 API 文档 / 层 API / 形状变换层 / Cropping3D 层

Cropping3D 层

[源文件]

Cropping3D

keras.layers.Cropping3D(
    cropping=((1, 1), (1, 1), (1, 1)), data_format=None, **kwargs
)

用于 3D 数据(例如空间或时空数据)的裁剪层。

示例

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

参数

  • cropping: 整型、包含 3 个整型的元组,或包含 3 个包含 2 个整型元组的元组。
    • 如果是整型:对深度、高度和宽度应用相同的对称裁剪。
    • 如果是包含 3 个整型的元组:解释为对深度、高度和宽度应用三个不同的对称裁剪值:(symmetric_dim1_crop, symmetric_dim2_crop, symmetric_dim3_crop)
    • 如果是包含 3 个包含 2 个整型元组的元组:解释为 ((left_dim1_crop, right_dim1_crop), (left_dim2_crop, right_dim2_crop), (left_dim3_crop, right_dim3_crop))
  • data_format: 字符串,可选值包括 "channels_last"(默认)或 "channels_first"。表示输入张量维度的顺序。"channels_last" 对应输入形状为 (batch_size, spatial_dim1, spatial_dim2, spatial_dim3, channels),而 "channels_first" 对应输入形状为 (batch_size, channels, spatial_dim1, spatial_dim2, spatial_dim3)。未指定时,使用 Keras 配置文件 ~/.keras/keras.json 中的 image_data_format 值(如果存在)。默认为 "channels_last"

输入形状

5D 张量,形状如下: - 如果 data_format"channels_last"(batch_size, first_axis_to_crop, second_axis_to_crop, third_axis_to_crop, channels) - 如果 data_format"channels_first"(batch_size, channels, first_axis_to_crop, second_axis_to_crop, third_axis_to_crop)

输出形状

5D 张量,形状如下: - 如果 data_format"channels_last"(batch_size, first_cropped_axis, second_cropped_axis, third_cropped_axis, channels) - 如果 data_format"channels_first"(batch_size, channels, first_cropped_axis, second_cropped_axis, third_cropped_axis)