RandomBrightness
类tf_keras.layers.RandomBrightness(factor, value_range=(0, 255), seed=None, **kwargs)
一个在训练期间随机调整亮度的预处理层。
此层将随机增加/减少输入 RGB 图像的亮度。在推断时,输出将与输入相同。调用此层时设置 training=True
以调整输入亮度。
请注意,不同的亮度调整因子将应用于批次中的每张图像。
有关预处理层的概述和完整列表,请参阅预处理指南。
参数
输入:3D (HWC) 或 4D (NHWC) 张量, dtype 为 float 或 int。输入像素值可以是任何范围(例如 [0., 1.)
或 [0, 255]
)
输出:根据 factor
调整亮度后的 3D (HWC) 或 4D (NHWC) 张量。默认情况下,该层将输出浮点数。输出值将被裁剪到 [0, 255]
范围(RGB 颜色的有效范围),并根据需要基于 value_range
进行缩放。
示例用法
random_bright = tf.keras.layers.RandomBrightness(factor=0.2)
# An image with shape [2, 2, 3]
image = [[[1, 2, 3], [4 ,5 ,6]], [[7, 8, 9], [10, 11, 12]]]
# Assume we randomly select the factor to be 0.1, then it will apply
# 0.1 * 255 to all the channel
output = random_bright(image, training=True)
# output will be int64 with 25.5 added to each channel and round down.
tf.Tensor([[[26.5, 27.5, 28.5]
[29.5, 30.5, 31.5]]
[[32.5, 33.5, 34.5]
[35.5, 36.5, 37.5]]],
shape=(2, 2, 3), dtype=int64)