1

I am trying to use Federated code to build my own federated learning algorithm. But I met one problem. In the official tutorial, it define the Model Spec like following:

MODEL_SPEC = collections.OrderedDict(
            filter1 = tf.TensorSpec(shape=weights[0].shape, dtype=tf.float32),
            bias1 = tf.TensorSpec(shape=weights[1].shape, dtype=tf.float32),
            filter2 = tf.TensorSpec(shape=weights[2].shape, dtype=tf.float32),
            bias2 = tf.TensorSpec(shape=weights[3].shape, dtype=tf.float32),
            weight1 = tf.TensorSpec(shape=weights[4].shape, dtype=tf.float32),
            bias3 = tf.TensorSpec(shape=weights[5].shape, dtype=tf.float32)
        )
        MODEL_TYPE = tff.to_type(MODEL_SPEC)

I am wondering if it is required to input the model as an OrderedDict. Could I input the model as a trainable Keras model?

Thanks!

jb4382
  • 19
  • 1

1 Answers1

1

Yes, TFF can work with models defined using tf.keras.Model (the functional or sequential APIs, not the subclass API) using the tff.learning.from_keras_model method.

This method is used in the Federated Learning for Text Generation and Building Your Own Federated Learning Algorithm tutorials.

Zachary Garrett
  • 2,911
  • 15
  • 23