This layer rescales every value of an input (often an image) by multiplying
by scale and adding offset.
For instance:
To rescale an input in the [0, 255] range
to be in the [0, 1] range, you would pass scale=1./255.
To rescale an input in the [0, 255] range to be in the [-1, 1] range,
you would pass scale=1./127.5, offset=-1.
The rescaling is applied both during training and inference. Inputs can be
of integer or floating point dtype, and by default the layer will output
floats.
Args
scale
Float, the scale to apply to the inputs.
offset
Float, the offset to apply to the inputs.
**kwargs
Base layer keyword arguments, such as name and dtype.
Attributes
input
Retrieves the input tensor(s) of a symbolic operation.
Only returns the tensor(s) corresponding to the first time
the operation was called.
output
Retrieves the output tensor(s) of a layer.
Only returns the tensor(s) corresponding to the first time
the operation was called.
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.Rescaling\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/rescaling.py#L6-L63) |\n\nA preprocessing layer which rescales input values to a new range.\n\nInherits From: [`Layer`](../../../tf/keras/Layer), [`Operation`](../../../tf/keras/Operation) \n\n tf.keras.layers.Rescaling(\n scale, offset=0.0, **kwargs\n )\n\n### Used in the notebooks\n\n| Used in the guide | Used in the tutorials |\n|----------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| - [Working with preprocessing layers](https://www.tensorflow.org/guide/keras/preprocessing_layers) | - [Image classification](https://www.tensorflow.org/tutorials/images/classification) - [Load and preprocess images](https://www.tensorflow.org/tutorials/load_data/images) - [Data augmentation](https://www.tensorflow.org/tutorials/images/data_augmentation) - [Transfer learning and fine-tuning](https://www.tensorflow.org/tutorials/images/transfer_learning) - [Transfer learning with TensorFlow Hub](https://www.tensorflow.org/tutorials/images/transfer_learning_with_hub) |\n\nThis layer rescales every value of an input (often an image) by multiplying\nby `scale` and adding `offset`.\n\n#### For instance:\n\n1. To rescale an input in the `[0, 255]` range\n to be in the `[0, 1]` range, you would pass `scale=1./255`.\n\n2. To rescale an input in the `[0, 255]` range to be in the `[-1, 1]` range,\n you would pass `scale=1./127.5, offset=-1`.\n\nThe rescaling is applied both during training and inference. Inputs can be\nof integer or floating point dtype, and by default the layer will output\nfloats.\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| `scale` | Float, the scale to apply to the inputs. |\n| `offset` | Float, the offset to apply to the inputs. |\n| `**kwargs` | Base layer keyword arguments, such as `name` and `dtype`. |\n\n\u003cbr /\u003e\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 )"]]