# tff.learning.algorithms.build_fed_eval

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

Builds a learning process that performs federated evaluation.

    tff.learning.algorithms.build_fed_eval(
        model_fn: Union[Callable[[], https://www.tensorflow.org/federated/api_docs/python/tff/learning/models/VariableModel], https://www.tensorflow.org/federated/api_docs/python/tff/learning/models/FunctionalModel],
        model_distributor: Optional[https://www.tensorflow.org/federated/api_docs/python/tff/learning/templates/DistributionProcess] = None,
        metrics_aggregation_process: Optional[https://www.tensorflow.org/federated/api_docs/python/tff/templates/AggregationProcess] = None,
        loop_implementation: https://www.tensorflow.org/federated/api_docs/python/tff/learning/LoopImplementation = https://www.tensorflow.org/federated/api_docs/python/tff/learning/LoopImplementation#DATASET_REDUCE
    ) -> https://www.tensorflow.org/federated/api_docs/python/tff/learning/templates/LearningProcess

### Used in the notebooks

| Used in the tutorials |
|---|
| - [Federated Learning for Image Classification](https://www.tensorflow.org/federated/tutorials/federated_learning_for_image_classification) |

This function creates a [`tff.learning.templates.LearningProcess`](https://www.tensorflow.org/federated/api_docs/python/tff/learning/templates/LearningProcess) that performs
federated evaluation on clients. The learning process has the following
methods inherited from [`tff.learning.templates.LearningProcess`](https://www.tensorflow.org/federated/api_docs/python/tff/learning/templates/LearningProcess):

- `initialize`: A [`tff.Computation`](https://www.tensorflow.org/federated/api_docs/python/tff/Computation) with type signature `( -> S@SERVER)`, where `S` is a [`tff.learning.templates.LearningAlgorithmState`](https://www.tensorflow.org/federated/api_docs/python/tff/learning/templates/LearningAlgorithmState) representing the initial state of the server.
- `next`: A [`tff.Computation`](https://www.tensorflow.org/federated/api_docs/python/tff/Computation) with type signature `(<S@SERVER, {B*}@CLIENTS> -> <L@SERVER>)` where `S` is a `LearningAlgorithmState` whose type matches that of the output of `initialize`, and `{B*}@CLIENTS` represents the client datasets, where `B` is the type of a single batch. The output `L` contains the updated server state, as well as aggregated metrics at the server, including client evaluation metrics and any other metrics from distribution and aggregation processes.
- `get_model_weights`: A [`tff.Computation`](https://www.tensorflow.org/federated/api_docs/python/tff/Computation) with type signature `(S -> M)`, where `S` is a [`tff.learning.templates.LearningAlgorithmState`](https://www.tensorflow.org/federated/api_docs/python/tff/learning/templates/LearningAlgorithmState) whose type matches the output of `initialize` and `next`, and `M` represents the type of the model weights used during evaluation.
- `set_model_weights`: A [`tff.Computation`](https://www.tensorflow.org/federated/api_docs/python/tff/Computation) with type signature `(<S, M> -> S)`, where `S` is a [`tff.learning.templates.LearningAlgorithmState`](https://www.tensorflow.org/federated/api_docs/python/tff/learning/templates/LearningAlgorithmState) whose type matches the output of `initialize` and `M` represents the type of the model weights used during evaluation.

Each time `next` is called, the server model is broadcast to each client using
a distributor. Each client evaluates the model and reports local unfinalized
metrics. The local unfinalized metrics are then aggregated and finalized at
server using the metrics aggregator. Both current round and total rounds
metrics will be produced. There are no update of the server model during the
evaluation process.

<br />

<br />

<br />

| ## Args ||
|---|---|
| `model_fn` | A no-arg function that returns a [`tff.learning.models.VariableModel`](https://www.tensorflow.org/federated/api_docs/python/tff/learning/models/VariableModel), or an instance of a [`tff.learning.models.FunctionalModel`](https://www.tensorflow.org/federated/api_docs/python/tff/learning/models/FunctionalModel). When passing a callable, the callable must *not* capture TensorFlow tensors or variables and use them. The model must be constructed entirely from scratch on each invocation, returning the same pre-constructed model each call will result in an error. |
| `model_distributor` | An optional [`tff.learning.templates.DistributionProcess`](https://www.tensorflow.org/federated/api_docs/python/tff/learning/templates/DistributionProcess) that broadcasts the model weights on the server to the clients. It must support the signature `(input_values@SERVER -> output_values@CLIENTS)` and have empty state. If None, the server model is broadcast to the clients using the default [`tff.federated_broadcast`](https://www.tensorflow.org/federated/api_docs/python/tff/federated_broadcast). |
| `metrics_aggregation_process` | An optional [`tff.templates.AggregationProcess`](https://www.tensorflow.org/federated/api_docs/python/tff/templates/AggregationProcess) which aggregates the local unfinalized metrics at clients to server and finalizes the metrics at server. The [`tff.templates.AggregationProcess`](https://www.tensorflow.org/federated/api_docs/python/tff/templates/AggregationProcess) accumulates unfinalized metrics across round in the state, and produces a tuple of current round metrics and total rounds metrics in the result. If None, the [`tff.templates.AggregationProcess`](https://www.tensorflow.org/federated/api_docs/python/tff/templates/AggregationProcess) created by the `SumThenFinalizeFactory` with metric finalizers defined in the model is used. |
| `loop_implementation` | Changes the implementation of the training loop generated. See [`tff.learning.LoopImplementation`](https://www.tensorflow.org/federated/api_docs/python/tff/learning/LoopImplementation) for more details. |

<br />

<br />

<br />

<br />

| ## Returns ||
|---|---|
| A [`tff.learning.templates.LearningProcess`](https://www.tensorflow.org/federated/api_docs/python/tff/learning/templates/LearningProcess) performs federated evaluation on clients, and returns updated state and metrics. ||

<br />

<br />

<br />

<br />

| ## Raises ||
|---|---|
| `TypeError` | If any argument type mismatches. |

<br />