Missed TensorFlow Dev Summit? Check out the video playlist. Watch recordings

tf_agents.metrics.tf_metrics.AverageReturnMetric

View source on GitHub

Metric to compute the average return.

Inherits From: TFStepMetric

tf_agents.metrics.tf_metrics.AverageReturnMetric(
    *args, **kwargs
)

Attributes:

  • name: Returns the name of this module as passed or determined in the ctor.

    NOTE: This is not the same as the self.name_scope.name which includes parent module names.

  • name_scope: Returns a tf.name_scope instance for this class.

  • submodules: Sequence of all sub-modules.

    Submodules are modules which are properties of this module, or found as properties of modules which are properties of this module (and so on).

a = tf.Module()
b = tf.Module()
c = tf.Module()
a.b = b
b.c = c
assert list(a.submodules) == [b, c]
assert list(b.submodules) == [c]
assert list(c.submodules) == []
  • trainable_variables: Sequence of trainable variables owned by this module and its submodules.

  • variables: Sequence of variables owned by this module and its submodules.

Methods

__call__

View source

__call__(
    *args, **kwargs
)

Returns op to execute to update this metric for these inputs.

Returns None if eager execution is enabled. Returns a graph-mode function if graph execution is enabled.

Args:

  • *args: * **kwargs: A mini-batch of inputs to the Metric, passed on to call().

call

View source

call(
    trajectory
)

init_variables

View source

init_variables()

Initializes this Metric's variables.

Should be called after variables are created in the first execution of __call__(). If using graph execution, the return value should be run() in a session before running the op returned by __call__(). (See example above.)

Returns:

If using graph execution, this returns an op to perform the initialization. Under eager execution, the variables are reset to their initial values as a side effect and this function returns None.

reset

View source

reset()

result

View source

result()

Computes and returns a final value for the metric.

tf_summaries

View source

tf_summaries(
    train_step=None, step_metrics=()
)

Generates summaries against train_step and all step_metrics.

Args:

  • train_step: (Optional) Step counter for training iterations. If None, no metric is generated against the global step.
  • step_metrics: (Optional) Iterable of step metrics to generate summaries against.

Returns:

A list of summaries.

with_name_scope

@classmethod
with_name_scope(
    cls, method
)

Decorator to automatically enter the module name scope.

class MyModule(tf.Module):
  @tf.Module.with_name_scope
  def __call__(self, x):
    if not hasattr(self, 'w'):
      self.w = tf.Variable(tf.random.normal([x.shape[1], 64]))
    return tf.matmul(x, self.w)

Using the above module would produce tf.Variables and tf.Tensors whose names included the module name:

mod = MyModule()
mod(tf.ones([8, 32]))
# ==> <tf.Tensor: ...>
mod.w
# ==> <tf.Variable ...'my_module/w:0'>

Args:

  • method: The method to wrap.

Returns:

The original method wrapped such that it enters the module's name scope.