tf.keras.metrics.MeanTensor
Stay organized with collections
Save and categorize content based on your preferences.
Computes the element-wise (weighted) mean of the given tensors.
Inherits From: Metric
tf.keras.metrics.MeanTensor(
name='mean_tensor', dtype=None
)
MeanTensor
returns a tensor with the same shape of the input tensors. The
mean value is updated by keeping local variables total
and count
. The
total
tracks the sum of the weighted values, and count
stores the sum of
the weighted counts.
Usage:
m = tf.keras.metrics.MeanTensor()
m.update_state([0, 1, 2, 3])
m.update_state([4, 5, 6, 7])
print('Result: ', m.result().numpy()) # Result: [2, 3, 4, 5]
m.update_state([12, 10, 8, 6], sample_weights= [0, 0.2, 0.5, 1])
print('Result: ', m.result().numpy()) # Result: [2, 3.636, 4.8, 5.333]
Args |
name
|
(Optional) string name of the metric instance.
|
dtype
|
(Optional) data type of the metric result.
|
Methods
reset_states
View source
reset_states()
Resets all of the metric state variables.
This function is called between epochs/steps,
when a metric is evaluated during training.
result
View source
result()
Computes and returns the metric value tensor.
Result computation is an idempotent operation that simply calculates the
metric value using the state variables.
update_state
View source
update_state(
values, sample_weight=None
)
Accumulates statistics for computing the element-wise mean.
Args |
values
|
Per-example value.
|
sample_weight
|
Optional weighting of each example. Defaults to 1.
|
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 2020-10-01 UTC.
[null,null,["Last updated 2020-10-01 UTC."],[],[],null,["# tf.keras.metrics.MeanTensor\n\n\u003cbr /\u003e\n\n|-------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------|\n| [TensorFlow 1 version](/versions/r1.15/api_docs/python/tf/keras/metrics/MeanTensor) | [View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.1.0/tensorflow/python/keras/metrics.py#L2585-L2692) |\n\nComputes the element-wise (weighted) mean of the given tensors.\n\nInherits From: [`Metric`](../../../tf/keras/metrics/Metric)\n\n#### View aliases\n\n\n**Main aliases**\n\n[`tf.metrics.MeanTensor`](/api_docs/python/tf/keras/metrics/MeanTensor)\n**Compat aliases for migration**\n\nSee\n[Migration guide](https://www.tensorflow.org/guide/migrate) for\nmore details.\n\n[`tf.compat.v1.keras.metrics.MeanTensor`](/api_docs/python/tf/keras/metrics/MeanTensor)\n\n\u003cbr /\u003e\n\n tf.keras.metrics.MeanTensor(\n name='mean_tensor', dtype=None\n )\n\n`MeanTensor` returns a tensor with the same shape of the input tensors. The\nmean value is updated by keeping local variables `total` and `count`. The\n`total` tracks the sum of the weighted values, and `count` stores the sum of\nthe weighted counts.\n\n#### Usage:\n\n m = tf.keras.metrics.MeanTensor()\n m.update_state([0, 1, 2, 3])\n m.update_state([4, 5, 6, 7])\n print('Result: ', m.result().numpy()) # Result: [2, 3, 4, 5]\n m.update_state([12, 10, 8, 6], sample_weights= [0, 0.2, 0.5, 1])\n print('Result: ', m.result().numpy()) # Result: [2, 3.636, 4.8, 5.333]\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|---------|------------------------------------------------|\n| `name` | (Optional) string name of the metric instance. |\n| `dtype` | (Optional) data type of the metric result. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Attributes ---------- ||\n|---------|---------------|\n| `count` | \u003cbr /\u003e \u003cbr /\u003e |\n| `total` | \u003cbr /\u003e \u003cbr /\u003e |\n\n\u003cbr /\u003e\n\nMethods\n-------\n\n### `reset_states`\n\n[View source](https://github.com/tensorflow/tensorflow/blob/v2.1.0/tensorflow/python/keras/metrics.py#L2689-L2692) \n\n reset_states()\n\nResets all of the metric state variables.\n\nThis function is called between epochs/steps,\nwhen a metric is evaluated during training.\n\n### `result`\n\n[View source](https://github.com/tensorflow/tensorflow/blob/v2.1.0/tensorflow/python/keras/metrics.py#L2681-L2687) \n\n result()\n\nComputes and returns the metric value tensor.\n\nResult computation is an idempotent operation that simply calculates the\nmetric value using the state variables.\n\n### `update_state`\n\n[View source](https://github.com/tensorflow/tensorflow/blob/v2.1.0/tensorflow/python/keras/metrics.py#L2638-L2679) \n\n update_state(\n values, sample_weight=None\n )\n\nAccumulates statistics for computing the element-wise mean.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ||\n|-----------------|----------------------------------------------------|\n| `values` | Per-example value. |\n| `sample_weight` | Optional weighting of each example. Defaults to 1. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ||\n|---|---|\n| Update op. ||\n\n\u003cbr /\u003e"]]