tf.keras.layers.RandomBrightness
Stay organized with collections
Save and categorize content based on your preferences.
A preprocessing layer which randomly adjusts brightness during training.
Inherits From: Layer
, Module
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.
Note that different brightness adjustment factors
will be apply to each the images in the batch.
For an overview and full list of preprocessing layers, see the preprocessing
guide.
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. Defaults to [0.0, 255.0]. Can be
changed to e.g. [0.0, 1.0] if the image input has been scaled before
this layer. 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.
Sample usage:
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)
Attributes |
auto_vectorize
|
Control whether automatic vectorization occurs.
By default the call() method leverages the tf.vectorized_map()
function. Auto-vectorization can be disabled by setting
self.auto_vectorize = False in your __init__() method. When
disabled, call() instead relies on tf.map_fn() . For example:
class SubclassLayer(BaseImageAugmentationLayer):
def __init__(self):
super().__init__()
self.auto_vectorize = False
|
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates. Some content is licensed under the numpy license.
Last updated 2022-10-28 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2022-10-28 UTC."],[],[],null,["# tf.keras.layers.RandomBrightness\n\n\u003cbr /\u003e\n\n|-----------------------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/keras-team/keras/tree/v2.11.0/keras/layers/preprocessing/image_preprocessing.py#L1615-L1764) |\n\nA preprocessing layer which randomly adjusts brightness during training.\n\nInherits From: [`Layer`](../../../tf/keras/layers/Layer), [`Module`](../../../tf/Module) \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\nNote that different brightness adjustment factors\nwill be apply to each the images in the batch.\n\nFor an overview and full list of preprocessing layers, see the preprocessing\n[guide](https://www.tensorflow.org/guide/keras/preprocessing_layers).\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. Defaults to \\[0.0, 255.0\\]. Can be changed to e.g. \\[0.0, 1.0\\] if the image input has been scaled before this layer. 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. The output value will\nbe clipped to the range `[0, 255]`, the valid range of RGB colors, and\nrescaled based on the `value_range` if needed.\n\n#### Sample usage:\n\n random_bright = tf.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 tf.Tensor([[[26.5, 27.5, 28.5]\n [29.5, 30.5, 31.5]]\n [[32.5, 33.5, 34.5]\n [35.5, 36.5, 37.5]]],\n shape=(2, 2, 3), dtype=int64)\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Attributes ---------- ||\n|------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `auto_vectorize` | Control whether automatic vectorization occurs. \u003cbr /\u003e By default the `call()` method leverages the [`tf.vectorized_map()`](../../../tf/vectorized_map) function. Auto-vectorization can be disabled by setting `self.auto_vectorize = False` in your `__init__()` method. When disabled, `call()` instead relies on [`tf.map_fn()`](../../../tf/map_fn). For example: class SubclassLayer(BaseImageAugmentationLayer): def __init__(self): super().__init__() self.auto_vectorize = False \u003cbr /\u003e |\n\n\u003cbr /\u003e"]]