【问题标题】:Access Clients Loss while having keras tff NN models拥有 keras tff NN 模型时访问客户端丢失
【发布时间】:2019-06-14 15:31:47
【问题描述】:

我试图在没有运气的情况下获得 tensorflow 模型中所有客户的损失。回复how to print local outputs in tensorflow federated? 建议从头开始创建我们的 NN 模型。但是,我已经有了我的 keras NN 模型。那么有没有办法在无需从头开始构建 NN 的情况下仍然可以访问本地客户损失?

我尝试使用 tff.federated_collect(),但不确定这怎么可能。

这部分是我的尝试:

    trainer_Itr_Process = tff.learning.build_federated_averaging_process(model_fn_Federated,server_optimizer_fn=(lambda : tf.keras.optimizers.SGD(learning_rate=learn_rate)),client_weight_fn=None)
    FLstate = trainer_Itr_Process.initialize()

    @tff.learning.Model
    def federated_output_computation():
        return{
            'num_examples': tff.federated_sum(metrics.num_examples),
            'loss': tff.federated_mean(metrics.loss, metrics.num_examples),
            'accuracy': tff.federated_mean(metrics.accuracy, metrics.num_examples),
            'per_client/num_examples': tff.federated_collect(metrics.num_examples),
            'per_client/loss': tff.federated_collect(metrics.loss),
            'per_client/accuracy': tff.federated_collect(metrics.accuracy),
            }

这是我收到的错误:

   @tff.learning.Model
TypeError: object() takes no parameters

【问题讨论】:

    标签: tensorflow-federated


    【解决方案1】:

    tff.learning.Model 不是函数的装饰器,它是tff.learning 模块使用的类接口。

    更改tff.learning.Model.federated_output_computation 的实现(how to print local outputs in tensorflow federated? 中推荐的方法)的最佳方法可能是创建您自己的tff.learning.Model 子类,该子类实现不同的federated_output_computation 属性。这将接近于重新实现tff.learning.from_keras_model(),除了提供自定义指标聚合;因此查看实现 (here) 可能很有用,但目前摄取 Keras 模型并非易事。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-08-17
      • 2018-01-31
      • 2019-02-20
      • 2019-10-25
      • 1970-01-01
      • 1970-01-01
      • 2018-10-19
      相关资源
      最近更新 更多