RandomZoom
类keras.layers.RandomZoom(
height_factor,
width_factor=None,
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.3, -0.2)
会导致输出在 [+20%, +30%]
范围内随机放大。width_factor=(0.2, 0.3)
会导致输出在 20% 到 30% 之间缩小。width_factor=(-0.3, -0.2)
会导致输出在 20% 到 30% 之间放大。None
表示保持纵横比,即垂直和水平方向同时缩放。默认为 None
。"constant"
、"nearest"
、"wrap"
和 "reflect"
。默认为 "reflect"
。"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)
通过使用 fill_value
指定的相同常量值 k 填充边缘之外的所有值来扩展输入。"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
。示例
>>> input_img = np.random.random((32, 224, 224, 3))
>>> layer = keras.layers.RandomZoom(.5, .2)
>>> out_img = layer(input_img)