# Module: tff.learning.metrics

<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/federated/blob/v0.87.0 Version 2.0, January 2004 Licensed under the Apache License, Version 2.0 (the) |

Libraries for working with metrics in federated learning algorithms.

## Classes

[`class FinalizeThenSampleFactory`](https://www.tensorflow.org/federated/api_docs/python/tff/learning/metrics/FinalizeThenSampleFactory): Aggregation Factory that finalizes and then samples the metrics.

[`class MetricsAggregatorType`](https://www.tensorflow.org/federated/api_docs/python/tff/learning/metrics/MetricsAggregatorType): Base class for protocol classes.

[`class NumBatchesCounter`](https://www.tensorflow.org/federated/api_docs/python/tff/learning/metrics/NumBatchesCounter): A [`tf.keras.metrics.Metric`](https://www.tensorflow.org/api_docs/python/tf/keras/Metric) that counts the number of batches seen.

[`class NumExamplesCounter`](https://www.tensorflow.org/federated/api_docs/python/tff/learning/metrics/NumExamplesCounter): A [`tf.keras.metrics.Metric`](https://www.tensorflow.org/api_docs/python/tf/keras/Metric) that counts the number of examples seen.

[`class SecureSumFactory`](https://www.tensorflow.org/federated/api_docs/python/tff/learning/metrics/SecureSumFactory): Aggregation Factory that performs secure summation over metrics.

[`class SumThenFinalizeFactory`](https://www.tensorflow.org/federated/api_docs/python/tff/learning/metrics/SumThenFinalizeFactory): Aggregation Factory that sums and then finalizes the metrics.

## Functions

[`create_default_secure_sum_quantization_ranges(...)`](https://www.tensorflow.org/federated/api_docs/python/tff/learning/metrics/create_default_secure_sum_quantization_ranges): Create a nested structure of quantization ranges for secure sum encoding.

[`create_functional_metric_fns(...)`](https://www.tensorflow.org/federated/api_docs/python/tff/learning/metrics/create_functional_metric_fns): Turn a Keras metric construction method into a tuple of pure functions.

[`create_keras_metric_finalizer(...)`](https://www.tensorflow.org/federated/api_docs/python/tff/learning/metrics/create_keras_metric_finalizer): Creates a finalizer function for the given Keras metric.

[`finalize_then_sample(...)`](https://www.tensorflow.org/federated/api_docs/python/tff/learning/metrics/finalize_then_sample): Creates a TFF computation to aggregate metrics via `finalize_then_sample`.

[`secure_sum_then_finalize(...)`](https://www.tensorflow.org/federated/api_docs/python/tff/learning/metrics/secure_sum_then_finalize): Creates a TFF computation that aggregates metrics using secure summation.

[`sum_then_finalize(...)`](https://www.tensorflow.org/federated/api_docs/python/tff/learning/metrics/sum_then_finalize): Creates a TFF computation that aggregates metrics via `sum_then_finalize`.

## Type Aliases

[`FunctionalMetricFinalizersType`](https://www.tensorflow.org/federated/api_docs/python/tff/learning/metrics/FunctionalMetricFinalizersType)

[`MetricFinalizersType`](https://www.tensorflow.org/federated/api_docs/python/tff/learning/metrics/MetricFinalizersType)