My goal is to load a base model from a .hdf5 file (it's a Keras model), and continue to train it with federated learning. Here is how I initialize the base model for FL:
def model_fn():
model = tf.keras.load_model(path/to/model.hdf5)
return tff.learning.from_keras_model(model=model,
dummy_batch=db,
loss=loss,
metrics=metrics)
trainer = tff.learning.build_federated_averaging_process(model_fn)
state = trainer.initialize()
However, it seems like the resulting state.model weights are randomly initialized, and are different from my saved model. When I evaluate the model's performance even before any federated training, it performs as a randomly initialized model: 50% accuracy. Here's how I evaluate the performance:
def evaluate(state):
keras_model = tf.keras.models.load_model(path/to/model.hdf5, compile=False)
tff.learning.assign_weights_to_keras_model(keras_model, state.model)
keras_model.compile(loss=loss, metrics=metrics)
return keras_model.evaluate(features, values)
How can I initialize a tff model with the saved model weights?