2

我是联邦学习的新手,我尝试实现 FL 的代码进行图像分类,但我无法理解这一行:state = iterative_process.initialize() ,权重从哪里影响到服务器?

4

1 回答 1

2

如何生成初始权重取决于tff.templates.IterativeProcess您所掌握的特定实现。使用tff.learning.build_federated_averaging_process,这些权重将与调用model_fn.

但是,如果您愿意,您可以控制这些语义。

例如,可以从磁盘加载权重:

@tff.tf_computation
def get_weights_from_disk():
  # load weights from wherever
  return loaded_weights

@tff.federated_computation
def server_init():
  # There may be state other than weights that needs to get returned from here,
  # as in the implementation of build_federated_averaging_process.
  return tff.federated_eval(get_weights_from_disk, tff.SERVER), ...

然后,您可以像这样创建一个新的迭代过程,只要我们上面编写的函数的类型签名与我们试图替换的迭代过程中的初始化函数的类型匹配:

old_iterproc = tff.learning.build_federated_averaging_process(...)
new_iterproc = tff.templates.IterativeProcess(intialize_fn=server_init,
  next_fn=old_iterproc.next)
于 2021-03-12T17:20:14.593 回答