Resizing 层

[源代码]

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(已批处理)张量,形状为:(..., height, width, channels),采用 "channels_last" 格式;或者 (..., channels, height, width),采用 "channels_first" 格式。

输出形状

3D(未批处理)或 4D(已批处理)张量,形状为:(..., target_height, target_width, channels),或者 (..., 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