RandomBrightness
類別keras.layers.RandomBrightness(factor, value_range=(0, 255), seed=None, **kwargs)
一個在訓練期間隨機調整亮度的預處理層。
此層將隨機增加/減少輸入 RGB 圖像的亮度。在推論時,輸出將與輸入相同。使用 training=True
調用此層以調整輸入的亮度。
注意: 此層可以安全地在 tf.data
管道內使用(與您使用的後端無關)。
參數
[0.0, 1.0]
,例如,如果圖像輸入在此層之前已縮放。預設值為 [0.0, 255.0]
。亮度調整將縮放到此範圍,並且輸出值將被裁剪到此範圍。輸入:3D (HWC) 或 4D (NHWC) 張量,具有浮點數或整數 dtype。輸入像素值可以是任何範圍(例如 [0., 1.)
或 [0, 255]
)
輸出:基於 factor
調整亮度的 3D (HWC) 或 4D (NHWC) 張量。預設情況下,此層將輸出浮點數。輸出值將被裁剪到範圍 [0, 255]
(RGB 顏色的有效範圍),並根據需要基於 value_range
重新縮放。
範例
random_bright = 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.
```python
>>> array([[[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)
```