View source on GitHub |
Wrapper for batching metrics.
Inherits From: PyStepMetric
, PyMetric
tf_agents.metrics.batched_py_metric.BatchedPyMetric(
metric_class: py_metric.PyMetric.__class__,
metric_args: Optional[Any] = None,
name: Optional[Text] = None,
batch_size: Optional[types.Int] = None,
dtype: np.dtype = np.float32,
prefix: Text = 'Metrics'
)
This can be used to wrap any python metric that takes a single trajectory to produce a batched version of the metric that takes a batch of trajectories.
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
@staticmethod
aggregate( metrics )
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. |
build
build(
batch_size: tf_agents.typing.types.Int
)
call
call(
batched_trajectory: tf_agents.trajectories.Trajectory
)
Processes the batched_trajectory to update the metric.
Args | |
---|---|
batched_trajectory
|
A Trajectory containing batches of experience. |
Raises | |
---|---|
ValueError
|
If the batch size is an unexpected value. |
log
log()
reset
reset()
Resets internal stat gathering variables used to compute the metric.
result
result() -> Any
Evaluates the current value of the metric.
tf_summaries
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. |
Returns | |
---|---|
The summary op. |
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__
__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. |