首页 > 解决方案 > 联邦学习中的MODEL_SPEC(使用Tensorflow Federated Core)

问题描述

我正在尝试使用联邦代码来构建我自己的联邦学习算法。但是我遇到了一个问题。在官方教程中,它定义了 Model Spec 如下:

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)

我想知道是否需要将模型作为 OrderedDict 输入。我可以将模型输入为可训练的 Keras 模型吗?

谢谢!

标签: tensorflowtensorflow-federatedfederated-learning

解决方案


是的,TFF 可以tf.keras.Model使用该方法与使用(功能或顺序 API,而不是子类 API)定义的模型一起使用tff.learning.from_keras_model

此方法用于文本生成的联邦学习构建您自己的联邦学习算法教程。


推荐阅读