Builds a tff.Computation
for evaluating a reconstruction Model
.
tff.learning.reconstruction.build_federated_evaluation(
model_fn: tff.learning.reconstruction.Model
,
*,
loss_fn: training_process.LossFn,
metrics_fn: Optional[training_process.MetricsFn] = None,
reconstruction_optimizer_fn: training_process.OptimizerFn = functools.partial(tf.keras.optimizers.SGD, 0.1),
dataset_split_fn: Optional[tff.learning.reconstruction.DatasetSplitFn
] = None,
broadcast_process: Optional[tff.templates.MeasuredProcess
] = None
) -> tff.Computation
Used in the notebooks
The returned computation proceeds in two stages: (1) reconstruction and (2)
evaluation. During the reconstruction stage, local variables are reconstructed
by freezing global variables and training using reconstruction_optimizer_fn
.
During the evaluation stage, the reconstructed local variables and global
variables are evaluated using the provided loss_fn
and metrics_fn
.
Usage of returned computation:
eval_comp = build_federated_evaluation(...)
metrics = eval_comp(tff.learning.reconstruction.get_global_variables(model),
federated_data)
Args |
model_fn
|
A no-arg function that returns a
tff.learning.reconstruction.Model . This method must not capture
Tensorflow tensors or variables and use them. Must be constructed entirely
from scratch on each invocation, returning the same pre-constructed model
each call will result in an error.
|
loss_fn
|
A no-arg function returning a tf.keras.losses.Loss to use to
reconstruct and evaluate the model. The loss will be applied to the
model's outputs during the evaluation stage. The final loss metric is the
example-weighted mean loss across batches (and across clients).
|
metrics_fn
|
A no-arg function returning a list of tf.keras.metrics.Metric s
to evaluate the model. The metrics will be applied to the model's outputs
during the evaluation stage. Final metric values are the example-weighted
mean of metric values across batches (and across clients). If None, no
metrics are applied.
|
reconstruction_optimizer_fn
|
A no-arg function that returns a
tf.keras.optimizers.Optimizer used to reconstruct the local variables
with the global ones frozen.
|
dataset_split_fn
|
A tff.learning.reconstruction.DatasetSplitFn taking in a
single TF dataset and producing two TF datasets. The first is iterated
over during reconstruction, and the second is iterated over during
evaluation. This can be used to preprocess datasets to e.g. iterate over
them for multiple epochs or use disjoint data for reconstruction and
evaluation. If None, split client data in half for each user, using one
half for reconstruction and the other for evaluation. See
tff.learning.reconstruction.build_dataset_split_fn for options.
|
broadcast_process
|
A tff.templates.MeasuredProcess that broadcasts the
model weights on the server to the clients. It must support the signature
(input_values@SERVER -> output_values@CLIENT) and have empty state. If
set to default None, the server model is broadcast to the clients using
the default tff.federated_broadcast .
|
Raises |
TypeError
|
if broadcast_process does not have the expected signature or
has non-empty state.
|
Returns |
A tff.Computation that accepts global model parameters and federated data
and returns example-weighted evaluation loss and metrics.
|