Running example code from Tensorflow documentation, pertaining to Tensorflow-Federated, results in AttributeError

41 Views Asked by At

I am trying to run the code given by Tensorflow in their official documentation, pertaining to Tensorflow-Federated. The code is as follows:

import tensorflow as tf
import tensorflow_federated as tff

training_process = tff.learning.algorithms.build_weighted_fed_avg(get_dense_nn, client_optimizer_fn=lambda: tf.keras.Sequential.SGD(learning_rate=client_lr),                                                                 server_optimizer_fn=lambda:tf.keras.optimizers.SGD(learning_rate=server_lr))

However, I am getting the following error:

AttributeError: module 'tensorflow_federated.python.learning' has no attribute 'from_keras_model'

Am I doing something wrong or is the documentation wrong?

1

There are 1 best solutions below

0
Zachary Garrett On

The error message indicates that tensorflow_federated.python.learning.from_keras_model is attempting to be used, however this API does not exist.

In newer versions of TensorFlow Federated, the API has moved to tff.learning.models.from_keras_model.