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.
Args
factor
Float or a list/tuple of 2 floats between -1.0 and 1.0. The
factor is used to determine the lower bound and upper bound of the
brightness adjustment. A float value will be chosen randomly between
the limits. When -1.0 is chosen, the output image will be black, and
when 1.0 is chosen, the image will be fully white.
When only one float is provided, eg, 0.2,
then -0.2 will be used for lower bound and 0.2
will be used for upper bound.
value_range
Optional list/tuple of 2 floats
for the lower and upper limit
of the values of the input data.
To make no change, use [0.0, 1.0], e.g., if the image input
has been scaled before this layer. Defaults to [0.0, 255.0].
The brightness adjustment will be scaled to this range, and the
output values will be clipped to this range.
seed
optional integer, for fixed RNG behavior.
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 channeloutput=random_bright(image,training=True)# output will be int64 with 25.5 added to each channel and round down.
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.
[null,null,["Last updated 2024-06-07 UTC."],[],[],null,["# tf.keras.layers.RandomBrightness\n\n\u003cbr /\u003e\n\n|--------------------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/keras-team/keras/tree/v3.3.3/keras/src/layers/preprocessing/random_brightness.py#L6-L164) |\n\nA preprocessing layer which randomly adjusts brightness during training.\n\nInherits From: [`Layer`](../../../tf/keras/Layer), [`Operation`](../../../tf/keras/Operation) \n\n tf.keras.layers.RandomBrightness(\n factor, value_range=(0, 255), seed=None, **kwargs\n )\n\nThis layer will randomly increase/reduce the brightness for the input RGB\nimages. At inference time, the output will be identical to the input.\nCall the layer with `training=True` to adjust the brightness of the input.\n| **Note:** This layer is safe to use inside a [`tf.data`](../../../tf/data) pipeline (independently of which backend you're using).\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|---------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `factor` | Float or a list/tuple of 2 floats between -1.0 and 1.0. The factor is used to determine the lower bound and upper bound of the brightness adjustment. A float value will be chosen randomly between the limits. When -1.0 is chosen, the output image will be black, and when 1.0 is chosen, the image will be fully white. When only one float is provided, eg, 0.2, then -0.2 will be used for lower bound and 0.2 will be used for upper bound. |\n| `value_range` | Optional list/tuple of 2 floats for the lower and upper limit of the values of the input data. To make no change, use `[0.0, 1.0]`, e.g., if the image input has been scaled before this layer. Defaults to `[0.0, 255.0]`. The brightness adjustment will be scaled to this range, and the output values will be clipped to this range. |\n| `seed` | optional integer, for fixed RNG behavior. |\n\n\u003cbr /\u003e\n\nInputs: 3D (HWC) or 4D (NHWC) tensor, with float or int dtype. Input pixel\nvalues can be of any range (e.g. `[0., 1.)` or `[0, 255]`)\n\nOutput: 3D (HWC) or 4D (NHWC) tensor with brightness adjusted based on the\n`factor`. By default, the layer will output floats.\nThe output value will be clipped to the range `[0, 255]`,\nthe valid range of RGB colors, and\nrescaled based on the `value_range` if needed.\n\n#### Example:\n\n random_bright = keras.layers.RandomBrightness(factor=0.2)\n\n # An image with shape [2, 2, 3]\n image = [[[1, 2, 3], [4 ,5 ,6]], [[7, 8, 9], [10, 11, 12]]]\n\n # Assume we randomly select the factor to be 0.1, then it will apply\n # 0.1 * 255 to all the channel\n output = random_bright(image, training=True)\n\n # output will be int64 with 25.5 added to each channel and round down.\n\n\u003e \u003e \u003e array(\\[\\[\\[26.5, 27.5, 28.5\\]\n\u003e \u003e \u003e \\[29.5, 30.5, 31.5\\]\\]\n\u003e \u003e \u003e \\[\\[32.5, 33.5, 34.5\\]\n\u003e \u003e \u003e \\[35.5, 36.5, 37.5\\]\\]\\],\nshape=(2, 2, 3), dtype=int64) \n\n```python\n\n```\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Attributes ---------- ||\n|----------|------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `input` | Retrieves the input tensor(s) of a symbolic operation. \u003cbr /\u003e Only returns the tensor(s) corresponding to the *first time* the operation was called. |\n| `output` | Retrieves the output tensor(s) of a layer. \u003cbr /\u003e Only returns the tensor(s) corresponding to the *first time* the operation was called. |\n\n\u003cbr /\u003e\n\nMethods\n-------\n\n### `from_config`\n\n[View source](https://github.com/keras-team/keras/tree/v3.3.3/keras/src/ops/operation.py#L191-L213) \n\n @classmethod\n from_config(\n config\n )\n\nCreates a layer from its config.\n\nThis method is the reverse of `get_config`,\ncapable of instantiating the same layer from the config\ndictionary. It does not handle layer connectivity\n(handled by Network), nor weights (handled by `set_weights`).\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ||\n|----------|----------------------------------------------------------|\n| `config` | A Python dictionary, typically the output of get_config. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ||\n|---|---|\n| A layer instance. ||\n\n\u003cbr /\u003e\n\n### `symbolic_call`\n\n[View source](https://github.com/keras-team/keras/tree/v3.3.3/keras/src/ops/operation.py#L58-L70) \n\n symbolic_call(\n *args, **kwargs\n )"]]