Replace deprecated API tff.learning.build_federarted_averaging_process() with new API.
Change `tff.learning.from_compiled_keras_model` to `tff.learning.from_keras_model`.
Supply `tff.learning.build_federated_averaging_process` with a `client_optimizer_fn` argument.
Cleanup usages of collections.OrdereDict to use ordered kwargs instead of list of tuples.
@@ -105,6 +105,7 @@ class FederatedEvaluationTest(test.TestCase):
def model_fn():
keras_model = tf.keras.Sequential([
+ tf.keras.layers.Input(shape=(1,)),
tf.keras.layers.Dense(
1,
kernel_initializer='ones',
@@ -112,16 +113,14 @@ class FederatedEvaluationTest(test.TestCase):
activation=None)
],
name='my_model')
- keras_model.compile(
- loss='mean_squared_error',
- optimizer='sgd',
- metrics=[tf.keras.metrics.Accuracy()])
- return keras_utils.from_compiled_keras_model(
+ return keras_utils.from_keras_model(
keras_model,
- dummy_batch=collections.OrderedDict([
- ('x', np.zeros((1, 1), np.float32)),
- ('y', np.zeros((1, 1), np.float32)),
- ]))
+ dummy_batch=collections.OrderedDict(
+ x=np.zeros((1, 1), np.float32),
+ y=np.zeros((1, 1), np.float32),
+ ),
+ loss=tf.keras.losses.MeanSquaredError(),
+ metrics=[tf.keras.metrics.Accuracy()])
evaluate_comp = federated_evaluation.build_federated_evaluation(model_fn)
initial_weights = tf.nest.map_structure(
