View source on GitHub |
A preprocessing layer which randomly adjusts brightness during training.
Inherits From: Layer
, Operation
tf.keras.layers.RandomBrightness(
factor, value_range=(0, 255), seed=None, **kwargs
)
This layer will randomly increase/reduce the brightness for the input RGB
images. At inference time, the output will be identical to the input.
Call the layer with training=True
to adjust the brightness of the input.
Inputs: 3D (HWC) or 4D (NHWC) tensor, with float or int dtype. Input pixel
values can be of any range (e.g. [0., 1.)
or [0, 255]
)
Output: 3D (HWC) or 4D (NHWC) tensor with brightness adjusted based on the
factor
. By default, the layer will output floats.
The output value will be clipped to the range [0, 255]
,
the valid range of RGB colors, and
rescaled based on the value_range
if needed.
Example:
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.
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)
Methods
from_config
@classmethod
from_config( config )
Creates a layer from its config.
This method is the reverse of get_config
,
capable of instantiating the same layer from the config
dictionary. It does not handle layer connectivity
(handled by Network), nor weights (handled by set_weights
).
Args | |
---|---|
config
|
A Python dictionary, typically the output of get_config. |
Returns | |
---|---|
A layer instance. |
symbolic_call
symbolic_call(
*args, **kwargs
)