1

I'm newer in TFF, I work on this tutorial. I would like to replace keras_evaluate function by predefined function of TFF : evaluation = tff.learning.build_federated_evaluation(model)

So how can I edit those lines :

def keras_evaluate(state, round_num):
  # Take our global model weights and push them back into a Keras model to
  # use its standard `.evaluate()` method.
  keras_model = load_model(batch_size=BATCH_SIZE)
  keras_model.compile(
      loss=tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True),
      metrics=[FlattenedCategoricalAccuracy()])
  state.model.assign_weights_to(keras_model)
  loss, accuracy = keras_model.evaluate(example_dataset, steps=2, verbose=0)
  print('\tEval: loss={l:.3f}, accuracy={a:.3f}'.format(l=loss, a=accuracy))


for round_num in range(NUM_ROUNDS):
  print('Round {r}'.format(r=round_num))
  keras_evaluate(state, round_num)
  state, metrics = fed_avg.next(state, train_datasets)
  train_metrics = metrics['train']
  print('\tTrain: loss={l:.3f}, accuracy={a:.3f}'.format(
      l=train_metrics['loss'], a=train_metrics['accuracy']))

print('Final evaluation')
keras_evaluate(state, NUM_ROUNDS + 1)

In this line :

loss, accuracy = keras_model.evaluate(example_dataset, steps=2, verbose=0)

the function evaluate only on an example of dataset contrary to build_federated_evaluation , it evaluate on federated_test_data totally. So how can I modify this function to evaluate on the totality of federated_test_data like in the other tutorial : test_metrics = evaluation(state.model, federated_test_data)

Zachary Garrett
  • 2,911
  • 15
  • 23
Eliza
  • 584
  • 4
  • 14

0 Answers0