【问题标题】:`tensorflow_federated.learning.from_keras_model()` no longer contains 'dummy_batch' keyword?`tensorflow_federated.learning.from_keras_model()` 不再包含 'dummy_batch' 关键字?
【发布时间】:2020-05-19 02:49:00
【问题描述】:

我在 https://colab.research.google.com/github/tensorflow/federated/blob/v0.13.1/docs/tutorials/federated_learning_for_image_classification.ipynb 上运行了 tensorflow 联合教程代码。我收到了这个错误

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-17-d5336a451ad0> in <module>()
      2     model_fn,
      3     client_optimizer_fn=lambda: tf.keras.optimizers.SGD(learning_rate=0.02),
----> 4     server_optimizer_fn=lambda: tf.keras.optimizers.SGD(learning_rate=1.0))

2 frames
<ipython-input-16-7b97120f96c2> in model_fn()
      7       dummy_batch=sample_batch,
      8       loss=tf.keras.losses.SparseCategoricalCrossentropy(),
----> 9       metrics=[tf.keras.metrics.SparseCategoricalAccuracy()])

TypeError: from_keras_model() got an unexpected keyword argument 'dummy_batch'

提供的笔记本将tensorflow_federated更新到最新版本,所以tff版本是0.14.0。那么在 0.14.0 版本中,我们不再需要喂 dummy batch 了吗?通常的 tff 工作管道是否发生了变化?

附:将tensorflow_federated 降级到版本 0.13.1 可以。

【问题讨论】:

    标签: tensorflow tensorflow-federated


    【解决方案1】:

    这是正确的; dummy_batch 关键字在 this commit 中被弃用,取而代之的是 input_spec,以获得额外的灵活性。

    有几种方法可以获得input_spec,包括直接从要输入模型的数组或张量中计算它,但最简单的是访问关联@987654327 的element_spec 属性@ 模型将在其上进行训练。

    至于 colab 本身的链接,看起来当 TFF 作为其今天发布的一部分更新其链接时,它在标记 GitHub 上的提交时忘记包含 v。链接现已更新,this 应该会将您带到适用于 0.14.0 的 colab 版本。

    【讨论】:

      猜你喜欢
      • 2016-10-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-12
      • 2011-06-11
      • 2018-08-14
      • 1970-01-01
      相关资源
      最近更新 更多