调整大小层

[源代码]

Resizing

keras.layers.Resizing(
    height,
    width,
    interpolation="bilinear",
    crop_to_aspect_ratio=False,
    pad_to_aspect_ratio=False,
    fill_mode="constant",
    fill_value=0.0,
    antialias=False,
    data_format=None,
    **kwargs
)

用于调整图像大小的预处理层。

此层将输入图像调整为目标高度和宽度。输入应为 "channels_last" 格式的 4D(批处理)或 3D(非批处理)张量。输入像素值可以是任何范围(例如 [0., 1.)[0, 255])。

输入形状

3D(非批处理)或 4D(批处理)张量,形状为:在 "channels_last" 格式下为 (..., height, width, channels),或在 "channels_first" 格式下为 (..., channels, height, width)

输出形状

3D(非批处理)或 4D(批处理)张量,形状为:(..., target_height, target_width, channels)(在 "channels_last" 格式下),或 (..., channels, target_height, target_width)(在 "channels_first" 格式下)。

注意:此层可在 tf.data 流水线中安全使用(无论您使用哪个后端)。

参数

  • height:整数,输出形状的高度。
  • width:整数,输出形状的宽度。
  • interpolation:字符串,插值方法。支持 "bilinear""nearest""bicubic""lanczos3""lanczos5"。默认为 "bilinear"
  • crop_to_aspect_ratio:如果为 True,则在不失真长宽比的情况下调整图像大小。当原始长宽比与目标长宽比不同时,输出图像将被裁剪,以便返回图像中与目标长宽比匹配的尽可能大的窗口(大小为 (height, width))。默认情况下(crop_to_aspect_ratio=False),可能不保留长宽比。
  • pad_to_aspect_ratio:如果为 True,则在不失真长宽比的情况下对图像进行填充。当原始长宽比与目标长宽比不同时,输出图像将在短边上进行均匀填充。
  • fill_mode:当使用 pad_to_aspect_ratio=True 时,填充区域根据给定模式填充。目前仅支持 "constant"(用常数值填充,等于 fill_value)。
  • fill_value:浮点数。当 pad_to_aspect_ratio=True 时使用的填充值。
  • data_format:字符串,可以是 "channels_last""channels_first"。输入中维度的顺序。"channels_last" 对应于形状为 (batch, height, width, channels) 的输入,而 "channels_first" 对应于形状为 (batch, channels, height, width) 的输入。它默认为 Keras 配置文件 ~/.keras/keras.json 中找到的 image_data_format 值。如果您从未设置它,则默认为 "channels_last"
  • **kwargs:基础层关键字参数,例如 namedtype