0

Attempting to run federated learning on tff however, encountering the following:

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

Code: trainer = tff.learning.algorithms.build_weighted_fed_avg( model_fn, client_optimizer_fn=lambda: tf.keras.optimizers.Adam(), server_optimizer_fn=lambda: tf.keras.optimizers.Adam() )

state = trainer.initialize() train_hist = [] for i in range(EPOCHS): state, metrics = trainer.next(state, train_data) train_hist.append(metrics)

print(f"\rRun {i+1}/{EPOCHS}", end="")

Environment: Using Google collab python - 3.10.12 TensorFlow Federated version: 0.61.0

Any help appreciated.

Attempted to downgrade version of TFF

1 Answer 1

0

Now "from_keras_model" is moved to "models". So, "tff.learning.from_keras_model" is replaced with "tff.learning.models.from_keras_model"

Old Code

  return tff.learning.from_keras_model(
      keras_model,
      input_spec=xxxxx,
      loss=tf.keras.losses.SparseCategoricalCrossentropy(),
      metrics=[tf.keras.metrics.SparseCategoricalAccuracy()])

NEW Code

  return tff.learning.models.from_keras_model(
      keras_model,
      input_spec=xxxxx,
      loss=tf.keras.losses.SparseCategoricalCrossentropy(),
      metrics=[tf.keras.metrics.SparseCategoricalAccuracy()])
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.