张量流联合:类型错误:<lambda>() 需要 0 个位置参数,但给出了 1 个



我使用的是tensorflow-federated版本0.28。我试图实现build_weighted_fed_avg_with_optimizer_schedule,但我得到以下错误:


Traceback (most recent call last):
File "/home/Desktop/FL/fedopt.py", line 340, in <module>
iterative_process = build_weighted_fed_avg_with_optimizer_schedule(
File "/home/anaconda3/envs/fl/lib/python3.9/site-packages/tensorflow_federated/python/learning/algorithms/fed_avg_with_optimizer_schedule.py", line 276, in build_weighted_fed_avg_with_optimizer_schedule
client_work = build_scheduled_client_work(model_fn, client_learning_rate_fn,
File "/home/anaconda3/envs/fl/lib/python3.9/site-packages/tensorflow_federated/python/learning/algorithms/fed_avg_with_optimizer_schedule.py", line 98, in build_scheduled_client_work
whimsy_optimizer = optimizer_fn(1.0)
TypeError: <lambda>() takes 0 positional arguments but 1 was given
我的代码如下:
iterative_process = build_weighted_fed_avg_with_optimizer_schedule(
model_fn,
client_learning_rate_fn = lambda x: 0.001,
client_optimizer_fn=lambda: optimizers.Adam(learning_rate= client_lr, beta_1 = 0.9, beta_2 = 0.999,epsilon = 1e-07),
server_optimizer_fn=lambda: optimizers.SGD(learning_rate= server_lr), 
use_experimental_simulation_loop=True)
谁能告诉我我在这里做错了什么?

在上面的代码中,您将lambda设置为接受参数x:

client_learning_rate_fn = lambda x: 0.001

您是否希望通过一些x0.001操纵,例如乘法?见下文:

client_learning_rate_fn = lambda x: x*0.001

编辑:修正语法错误

相关内容

  • 没有找到相关文章

最新更新