0

I'm new in Federated learning, I tried to implement the code of FL for Image Classification, but I can't understand this line

I am confused in some detail parts. I am trying to build a sequential model in Keras, but when I train the model, I am getting this error, How may I fix it?

please guide me thank you.

iterative_process = tff.learning.build_federated_averaging_process(model_fn)

TypeError                                 Traceback (most recent call last)
<ipython-input-50-0fdb188570d0> in <module>()
----> 1 iterative_process = tff.learning.build_federated_averaging_process(model_fn)

TypeError: build_federated_averaging_process() missing 1 required positional argument: 'client_optimizer_fn'

https://colab.research.google.com/github/tensorflow/federated/blob/v0.12.0/docs/tutorials/federated_learning_for_image_classification.ipynb#scrollTo=sk6mjOfycX5N

Zachary Garrett
  • 2,911
  • 15
  • 23

1 Answers1

3

This is an error from python about the function call, see this answer and question for a similar scenario.

The API documentation for tff.learning.build_federated_averaging_process indicates that two arguments are required: a model_fn argument and a client_optimizer_fn.

From the code, it looks like only the first argument is specified. The colab notebook link above points to an older version of TFF (0.12.0, most recent is 0.19.0). The old version of the colab notebook is not guaranteed with newer versions of the PIP package.

In the newer colab notebook version the call has been updated to match the current API and includes additional parameters:

iterative_process = tff.learning.build_federated_averaging_process(
    model_fn,
    client_optimizer_fn=lambda: tf.keras.optimizers.SGD(learning_rate=0.02),
    server_optimizer_fn=lambda: tf.keras.optimizers.SGD(learning_rate=1.0))
Zachary Garrett
  • 2,911
  • 15
  • 23