tf_agents.utils.tensor_normalizer.TensorNormalizer
Stay organized with collections
Save and categorize content based on your preferences.
Encapsulates tensor normalization and owns normalization variables.
tf_agents.utils.tensor_normalizer.TensorNormalizer(
tensor_spec, scope='normalize_tensor'
)
Example usage:
tensor_normalizer = StreamingTensorNormalizer(
tf.TensorSpec([], tf.float32))
observation_list = [list of float32 scalars or batches]
normalized_list = []
for o in observation_list:
normalized_list.append(tensor_normalizer.normalize(o))
tensor_normalizer.update(o)
tensor_normalizer = StreamingTensorNormalizer(
tf.TensorSpec([], tf.float64), dtype=tf.float64)
observation_list = [list of float64 scalars or batches]
for o in observation_list:
normalized_list.append(tensor_normalizer.normalize(o))
tensor_normalizer.update(o)
<!-- Tabular view -->
<table class="responsive fixed orange">
<colgroup><col width="214px"><col></colgroup>
<tr><th colspan="2"><h2 class="add-link">Args</h2></th></tr>
<tr>
<td>
`tensor_spec`<a id="tensor_spec"></a>
</td>
<td>
The specs of the tensors to normalize.
</td>
</tr><tr>
<td>
`scope`<a id="scope"></a>
</td>
<td>
Scope for the `tf.Module`.
</td>
</tr>
</table>
## Methods
<h3 id="map_dtype"><code>map_dtype</code></h3>
<a target="_blank" class="external" href="https://github.com/tensorflow/agents/blob/v0.19.0/tf_agents/utils/tensor_normalizer.py#L89-L91">View source</a>
<pre class="devsite-click-to-copy prettyprint lang-py tfo-signature-link">
<code>map_dtype(
dtype
)
</code></pre>
<h3 id="normalize"><code>normalize</code></h3>
<a target="_blank" class="external" href="https://github.com/tensorflow/agents/blob/v0.19.0/tf_agents/utils/tensor_normalizer.py#L134-L205">View source</a>
<pre class="devsite-click-to-copy prettyprint lang-py tfo-signature-link">
<code>normalize(
tensor, clip_value=5.0, center_mean=True, variance_epsilon=0.001
)
</code></pre>
Applies normalization to tensor.
<!-- Tabular view -->
<table class="responsive fixed orange">
<colgroup><col width="214px"><col></colgroup>
<tr><th colspan="2">Args</th></tr>
<tr>
<td>
`tensor`
</td>
<td>
Tensor to normalize.
</td>
</tr><tr>
<td>
`clip_value`
</td>
<td>
Clips normalized observations between +/- this value if
clip_value > 0, otherwise does not apply clipping.
</td>
</tr><tr>
<td>
`center_mean`
</td>
<td>
If true, subtracts off mean from normalized tensor.
</td>
</tr><tr>
<td>
`variance_epsilon`
</td>
<td>
Epsilon to avoid division by zero in normalization.
</td>
</tr>
</table>
<!-- Tabular view -->
<table class="responsive fixed orange">
<colgroup><col width="214px"><col></colgroup>
<tr><th colspan="2">Returns</th></tr>
<tr>
<td>
`normalized_tensor`
</td>
<td>
Tensor after applying normalization.
</td>
</tr>
</table>
<h3 id="update"><code>update</code></h3>
<a target="_blank" class="external" href="https://github.com/tensorflow/agents/blob/v0.19.0/tf_agents/utils/tensor_normalizer.py#L119-L132">View source</a>
<pre class="devsite-click-to-copy prettyprint lang-py tfo-signature-link">
<code>update(
tensor, outer_dims=(0,)
)
</code></pre>
Updates tensor normalizer variables.
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.
Last updated 2024-04-26 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 2024-04-26 UTC."],[],[],null,["# tf_agents.utils.tensor_normalizer.TensorNormalizer\n\n\u003cbr /\u003e\n\n|--------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/agents/blob/v0.19.0/tf_agents/utils/tensor_normalizer.py#L45-L205) |\n\nEncapsulates tensor normalization and owns normalization variables. \n\n tf_agents.utils.tensor_normalizer.TensorNormalizer(\n tensor_spec, scope='normalize_tensor'\n )\n\n#### Example usage:\n\n tensor_normalizer = StreamingTensorNormalizer(\n tf.TensorSpec([], tf.float32))\n observation_list = [list of float32 scalars or batches]\n normalized_list = []\n\n for o in observation_list:\n normalized_list.append(tensor_normalizer.normalize(o))\n tensor_normalizer.update(o)\n\n#### For float64 inputs do:\n\n tensor_normalizer = StreamingTensorNormalizer(\n tf.TensorSpec([], tf.float64), dtype=tf.float64)\n observation_list = [list of float64 scalars or batches]\n\n for o in observation_list:\n normalized_list.append(tensor_normalizer.normalize(o))\n tensor_normalizer.update(o)\n\n \u003c!-- Tabular view --\u003e\n \u003ctable class=\"responsive fixed orange\"\u003e\n \u003ccolgroup\u003e\u003ccol width=\"214px\"\u003e\u003ccol\u003e\u003c/colgroup\u003e\n \u003ctr\u003e\u003cth colspan=\"2\"\u003e\u003ch2 class=\"add-link\"\u003eArgs\u003c/h2\u003e\u003c/th\u003e\u003c/tr\u003e\n\n \u003ctr\u003e\n \u003ctd\u003e\n `tensor_spec`\u003ca id=\"tensor_spec\"\u003e\u003c/a\u003e\n \u003c/td\u003e\n \u003ctd\u003e\n The specs of the tensors to normalize.\n \u003c/td\u003e\n \u003c/tr\u003e\u003ctr\u003e\n \u003ctd\u003e\n `scope`\u003ca id=\"scope\"\u003e\u003c/a\u003e\n \u003c/td\u003e\n \u003ctd\u003e\n Scope for the `tf.Module`.\n \u003c/td\u003e\n \u003c/tr\u003e\n \u003c/table\u003e\n\n\n\n ## Methods\n\n \u003ch3 id=\"map_dtype\"\u003e\u003ccode\u003emap_dtype\u003c/code\u003e\u003c/h3\u003e\n\n \u003ca target=\"_blank\" class=\"external\" href=\"https://github.com/tensorflow/agents/blob/v0.19.0/tf_agents/utils/tensor_normalizer.py#L89-L91\"\u003eView source\u003c/a\u003e\n\n \u003cpre class=\"devsite-click-to-copy prettyprint lang-py tfo-signature-link\"\u003e\n \u003ccode\u003emap_dtype(\n dtype\n )\n \u003c/code\u003e\u003c/pre\u003e\n\n\n\n\n \u003ch3 id=\"normalize\"\u003e\u003ccode\u003enormalize\u003c/code\u003e\u003c/h3\u003e\n\n \u003ca target=\"_blank\" class=\"external\" href=\"https://github.com/tensorflow/agents/blob/v0.19.0/tf_agents/utils/tensor_normalizer.py#L134-L205\"\u003eView source\u003c/a\u003e\n\n \u003cpre class=\"devsite-click-to-copy prettyprint lang-py tfo-signature-link\"\u003e\n \u003ccode\u003enormalize(\n tensor, clip_value=5.0, center_mean=True, variance_epsilon=0.001\n )\n \u003c/code\u003e\u003c/pre\u003e\n\n Applies normalization to tensor.\n\n\n \u003c!-- Tabular view --\u003e\n \u003ctable class=\"responsive fixed orange\"\u003e\n \u003ccolgroup\u003e\u003ccol width=\"214px\"\u003e\u003ccol\u003e\u003c/colgroup\u003e\n \u003ctr\u003e\u003cth colspan=\"2\"\u003eArgs\u003c/th\u003e\u003c/tr\u003e\n\n \u003ctr\u003e\n \u003ctd\u003e\n `tensor`\n \u003c/td\u003e\n \u003ctd\u003e\n Tensor to normalize.\n \u003c/td\u003e\n \u003c/tr\u003e\u003ctr\u003e\n \u003ctd\u003e\n `clip_value`\n \u003c/td\u003e\n \u003ctd\u003e\n Clips normalized observations between +/- this value if\n clip_value \u003e 0, otherwise does not apply clipping.\n \u003c/td\u003e\n \u003c/tr\u003e\u003ctr\u003e\n \u003ctd\u003e\n `center_mean`\n \u003c/td\u003e\n \u003ctd\u003e\n If true, subtracts off mean from normalized tensor.\n \u003c/td\u003e\n \u003c/tr\u003e\u003ctr\u003e\n \u003ctd\u003e\n `variance_epsilon`\n \u003c/td\u003e\n \u003ctd\u003e\n Epsilon to avoid division by zero in normalization.\n \u003c/td\u003e\n \u003c/tr\u003e\n \u003c/table\u003e\n\n\n\n \u003c!-- Tabular view --\u003e\n \u003ctable class=\"responsive fixed orange\"\u003e\n \u003ccolgroup\u003e\u003ccol width=\"214px\"\u003e\u003ccol\u003e\u003c/colgroup\u003e\n \u003ctr\u003e\u003cth colspan=\"2\"\u003eReturns\u003c/th\u003e\u003c/tr\u003e\n\n \u003ctr\u003e\n \u003ctd\u003e\n `normalized_tensor`\n \u003c/td\u003e\n \u003ctd\u003e\n Tensor after applying normalization.\n \u003c/td\u003e\n \u003c/tr\u003e\n \u003c/table\u003e\n\n\n\n \u003ch3 id=\"update\"\u003e\u003ccode\u003eupdate\u003c/code\u003e\u003c/h3\u003e\n\n \u003ca target=\"_blank\" class=\"external\" href=\"https://github.com/tensorflow/agents/blob/v0.19.0/tf_agents/utils/tensor_normalizer.py#L119-L132\"\u003eView source\u003c/a\u003e\n\n \u003cpre class=\"devsite-click-to-copy prettyprint lang-py tfo-signature-link\"\u003e\n \u003ccode\u003eupdate(\n tensor, outer_dims=(0,)\n )\n \u003c/code\u003e\u003c/pre\u003e\n\n Updates tensor normalizer variables."]]