RandomBrightness
類別tf_keras.layers.RandomBrightness(factor, value_range=(0, 255), seed=None, **kwargs)
一個在訓練期間隨機調整亮度的預處理圖層。
此圖層將隨機增加/減少輸入 RGB 圖像的亮度。在推論時,輸出將與輸入相同。調用圖層時,使用 training=True
來調整輸入的亮度。
請注意,不同的亮度調整因子將應用於批次中的每個圖像。
有關預處理圖層的概述和完整列表,請參閱預處理指南。
引數
輸入:3D (HWC) 或 4D (NHWC) 張量,具有浮點數或整數資料類型。輸入像素值可以是任何範圍(例如 [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)