RandomBrightness
类tf_keras.layers.RandomBrightness(factor, value_range=(0, 255), seed=None, **kwargs)
一个在训练期间随机调整亮度的预处理层。
此层将随机增加/减少输入 RGB 图像的亮度。在推理时,输出将与输入相同。使用 training=True
调用该层以调整输入的亮度。
请注意,批次中的每个图像都会应用不同的亮度调整因子。
有关预处理层的概述和完整列表,请参阅预处理指南。
参数
输入: 3D (HWC) 或 4D (NHWC) 张量,数据类型为浮点数或整数。输入像素值可以是任何范围(例如 [0., 1.)
或 [0, 255]
)。
输出: 3D (HWC) 或 4D (NHWC) 张量,亮度根据 factor
进行调整。默认情况下,该层将输出浮点数。输出值将被裁剪至范围 [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)