tensorflow - 联邦学习中的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 模型吗?
谢谢!
解决方案
是的,TFF 可以tf.keras.Model
使用该方法与使用(功能或顺序 API,而不是子类 API)定义的模型一起使用tff.learning.from_keras_model
。
此方法用于文本生成的联邦学习和构建您自己的联邦学习算法教程。
推荐阅读
- python - 如何从每类 imagenet 中获取 50 个样本?
- wpf - UserControl 'Loaded' 上的 EventTrigger 未调用 ICommand.Execute
- c - 为什么我没有得到正确的总和值?
- dependency-injection - CDI注入具体接口实现
- reactjs - 在标签旁边创建 MUI 文本字段
- ansible - 如何在具有 python 2.4 的远程服务器上进行 ansible 工作
- javascript - 所需的 JSON 文件具有运行程序之前的旧值
- apache - 使用带参数的 htaccess 重写路径
- types - SBCL 注意:类型断言太复杂,无法检查
- kubernetes - 具有资源配额的 kubernetes pod 调度