RandomTranslation
类keras.layers.RandomTranslation(
height_factor,
width_factor,
fill_mode="reflect",
interpolation="bilinear",
seed=None,
fill_value=0.0,
data_format=None,
**kwargs
)
一个预处理层,在训练期间随机平移图像。
此层将在训练期间对每个图像应用随机平移,并根据 fill_mode
填充空白区域。
输入像素值可以是任何范围(例如 [0., 1.)
或 [0, 255]
),并且可以是整数或浮点 dtype。 默认情况下,该层将输出浮点数。
输入形状
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_factor=(-0.2, 0.3)
会导致输出在 [-20%, +30%]
范围内随机平移。height_factor=0.2
会导致输出高度在 [-20%, +20%]
范围内随机平移。width_factor=(-0.2, 0.3)
会导致输出向左平移 20%,向右平移 30%。width_factor=0.2
会导致输出高度向左或向右平移 20%。"constant"
、"nearest"
、"wrap"
和 "reflect"
。默认为 "constant"
。"reflect"
:(d c b a | a b c d | d c b a)
输入通过围绕最后一个像素的边缘反射来扩展。"constant"
:(k k k k | a b c d | k k k k)
输入通过用相同的常数值 k(由 fill_value
指定)填充边缘之外的所有值来扩展。"wrap"
:(a b c d | a b c d | a b c d)
输入通过环绕到相对的边缘来扩展。"nearest"
:(a a a a | a b c d | d d d d)
输入通过最近的像素扩展。 请注意,当使用 torch 后端时,"reflect"
会重定向到 "mirror"
(c d c b | a b c d | c b a b)
,因为 torch 不支持 "reflect"
。 请注意,torch 后端不支持 "wrap"
。"nearest"
、"bilinear"
。fill_mode="constant"
时要填充到边界外的值。"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"
。name
和 dtype
。