tf_agents.metrics.py_metrics.CounterMetric
Stay organized with collections
Save and categorize content based on your preferences.
Metric to track an arbitrary counter.
Inherits From: PyMetric
tf_agents.metrics.py_metrics.CounterMetric(
name: Text = 'Counter'
)
This is useful for, e.g., tracking the current train/eval iteration number.
To increment the counter, you can call it (e.g. metric_obj()).
Attributes |
prefix
|
Prefix for the metric.
|
summary_op
|
TF summary op for this metric.
|
summary_placeholder
|
TF placeholder to be used for the result of this metric.
|
Methods
aggregate
View source
@staticmethod
aggregate(
metrics: Sequence[tf_agents.metrics.py_metric.PyMetricType
]
) -> tf_agents.typing.types.Float
Aggregates a list of metrics.
The default behaviour is to return the average of the metrics.
Args |
metrics
|
a list of metrics, of the same class.
|
Returns |
The result of aggregating this metric.
|
call
View source
call()
log
View source
log()
reset
View source
reset()
Resets internal stat gathering variables used to compute the metric.
result
View source
result() -> np.int64
Evaluates the current value of the metric.
tf_summaries
View source
tf_summaries(
train_step: tf_agents.typing.types.Int
= None,
step_metrics: Sequence[tf_agents.metrics.py_metric.MetricType
] = ()
) -> tf.Operation
Build TF summary op and placeholder for this metric.
To execute the op, call py_metric.run_summaries.
Args |
train_step
|
Step counter for training iterations. If None, no metric is
generated against the global step.
|
step_metrics
|
Step values to plot as X axis in addition to global_step.
|
Raises |
RuntimeError
|
If this method has already been called (it can only be
called once).
|
ValueError
|
If any item in step_metrics is not of type PyMetric or
tf_metric.TFStepMetric.
|
__call__
View source
__call__(
*args
)
Method to update the metric contents.
To change the behavior of this function, override the call method.
Different subclasses might use this differently. For instance, the
PyStepMetric takes in a trajectory, while the CounterMetric takes no
parameters.
Args |
*args
|
See call method of subclass for specific arguments.
|
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.metrics.py_metrics.CounterMetric\n\n\u003cbr /\u003e\n\n|----------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/agents/blob/v0.19.0/tf_agents/metrics/py_metrics.py#L280-L301) |\n\nMetric to track an arbitrary counter.\n\nInherits From: [`PyMetric`](../../../tf_agents/metrics/py_metric/PyMetric) \n\n tf_agents.metrics.py_metrics.CounterMetric(\n name: Text = 'Counter'\n )\n\nThis is useful for, e.g., tracking the current train/eval iteration number.\n\nTo increment the counter, you can **call** it (e.g. metric_obj()).\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Attributes ---------- ||\n|-----------------------|----------------------------------------------------------|\n| `prefix` | Prefix for the metric. |\n| `summary_op` | TF summary op for this metric. |\n| `summary_placeholder` | TF placeholder to be used for the result of this metric. |\n\n\u003cbr /\u003e\n\nMethods\n-------\n\n### `aggregate`\n\n[View source](https://github.com/tensorflow/agents/blob/v0.19.0/tf_agents/metrics/py_metric.py#L186-L198) \n\n @staticmethod\n aggregate(\n metrics: Sequence[../../../tf_agents/metrics/py_metric#PyMetricType]\n ) -\u003e ../../../tf_agents/typing/types/Float\n\nAggregates a list of metrics.\n\nThe default behaviour is to return the average of the metrics.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ||\n|-----------|---------------------------------------|\n| `metrics` | a list of metrics, of the same class. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ||\n|---|---|\n| The result of aggregating this metric. ||\n\n\u003cbr /\u003e\n\n### `call`\n\n[View source](https://github.com/tensorflow/agents/blob/v0.19.0/tf_agents/metrics/py_metrics.py#L297-L298) \n\n call()\n\n### `log`\n\n[View source](https://github.com/tensorflow/agents/blob/v0.19.0/tf_agents/metrics/py_metric.py#L103-L105) \n\n log()\n\n### `reset`\n\n[View source](https://github.com/tensorflow/agents/blob/v0.19.0/tf_agents/metrics/py_metrics.py#L294-L295) \n\n reset()\n\nResets internal stat gathering variables used to compute the metric.\n\n### `result`\n\n[View source](https://github.com/tensorflow/agents/blob/v0.19.0/tf_agents/metrics/py_metrics.py#L300-L301) \n\n result() -\u003e np.int64\n\nEvaluates the current value of the metric.\n\n### `tf_summaries`\n\n[View source](https://github.com/tensorflow/agents/blob/v0.19.0/tf_agents/metrics/py_metric.py#L107-L165) \n\n tf_summaries(\n train_step: ../../../tf_agents/typing/types/Int = None,\n step_metrics: Sequence[../../../tf_agents/metrics/py_metric/MetricType] = ()\n ) -\u003e tf.Operation\n\nBuild TF summary op and placeholder for this metric.\n\nTo execute the op, call py_metric.run_summaries.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ||\n|----------------|------------------------------------------------------------------------------------------------|\n| `train_step` | Step counter for training iterations. If None, no metric is generated against the global step. |\n| `step_metrics` | Step values to plot as X axis in addition to global_step. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ||\n|---|---|\n| The summary op. ||\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Raises ||\n|----------------|--------------------------------------------------------------------------------|\n| `RuntimeError` | If this method has already been called (it can only be called once). |\n| `ValueError` | If any item in step_metrics is not of type PyMetric or tf_metric.TFStepMetric. |\n\n\u003cbr /\u003e\n\n### `__call__`\n\n[View source](https://github.com/tensorflow/agents/blob/v0.19.0/tf_agents/metrics/py_metric.py#L200-L212) \n\n __call__(\n *args\n )\n\nMethod to update the metric contents.\n\nTo change the behavior of this function, override the call method.\n\nDifferent subclasses might use this differently. For instance, the\nPyStepMetric takes in a trajectory, while the CounterMetric takes no\nparameters.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ||\n|---------|-----------------------------------------------------|\n| `*args` | See call method of subclass for specific arguments. |\n\n\u003cbr /\u003e"]]