# tf_agents.metrics.py_metrics.NumberOfEpisodes

<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/agents/blob/v0.19.0/tf_agents/metrics/py_metrics.py#L257-L277) |

Counts the number of episodes in the environment.

Inherits From: [`PyStepMetric`](https://www.tensorflow.org/agents/api_docs/python/tf_agents/metrics/py_metric/PyStepMetric), [`PyMetric`](https://www.tensorflow.org/agents/api_docs/python/tf_agents/metrics/py_metric/PyMetric)

    tf_agents.metrics.py_metrics.NumberOfEpisodes(
        name: Text = 'NumberOfEpisodes'
    )

<br />

<br />

<br />

| ## 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. |

<br />

## Methods

### `aggregate`

[View source](https://github.com/tensorflow/agents/blob/v0.19.0/tf_agents/metrics/py_metric.py#L186-L198)

    @staticmethod
    aggregate(
        metrics: Sequence[https://www.tensorflow.org/agents/api_docs/python/tf_agents/metrics/py_metric#PyMetricType]
    ) -> https://www.tensorflow.org/agents/api_docs/python/tf_agents/typing/types/Float

Aggregates a list of metrics.

The default behaviour is to return the average of the metrics.

<br />

<br />

<br />

| Args ||
|---|---|
| `metrics` | a list of metrics, of the same class. |

<br />

<br />

<br />

<br />

| Returns ||
|---|---|
| The result of aggregating this metric. ||

<br />

### `call`

[View source](https://github.com/tensorflow/agents/blob/v0.19.0/tf_agents/metrics/py_metrics.py#L272-L277)

    call(
        trajectory: https://www.tensorflow.org/agents/api_docs/python/tf_agents/trajectories/Trajectory
    )

Processes a trajectory to update the metric.

<br />

<br />

<br />

| Args ||
|---|---|
| `trajectory` | A trajectory.Trajectory. |

<br />

### `log`

[View source](https://github.com/tensorflow/agents/blob/v0.19.0/tf_agents/metrics/py_metric.py#L103-L105)

    log()

### `reset`

[View source](https://github.com/tensorflow/agents/blob/v0.19.0/tf_agents/metrics/py_metrics.py#L266-L267)

    reset()

Resets internal stat gathering variables used to compute the metric.

### `result`

[View source](https://github.com/tensorflow/agents/blob/v0.19.0/tf_agents/metrics/py_metrics.py#L269-L270)

    result() -> np.int64

Evaluates the current value of the metric.

### `tf_summaries`

[View source](https://github.com/tensorflow/agents/blob/v0.19.0/tf_agents/metrics/py_metric.py#L107-L165)

    tf_summaries(
        train_step: https://www.tensorflow.org/agents/api_docs/python/tf_agents/typing/types/Int = None,
        step_metrics: Sequence[https://www.tensorflow.org/agents/api_docs/python/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.

<br />

<br />

<br />

| 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. |

<br />

<br />

<br />

<br />

| Returns ||
|---|---|
| The summary op. ||

<br />

<br />

<br />

<br />

| 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. |

<br />

### `__call__`

[View source](https://github.com/tensorflow/agents/blob/v0.19.0/tf_agents/metrics/py_metric.py#L200-L212)

    __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.

<br />

<br />

<br />

| Args ||
|---|---|
| `*args` | See call method of subclass for specific arguments. |

<br />