运行来自Tensorflow文档的示例代码时出现AttributeError
我正在尝试运行Tensorflow官方文档中关于Tensorflow-Federated的代码,代码如下:
import tensorflow as tf
import tensorflow_federated as tff
training_process = tff.learning.algorithms.build_weighted_fed_avg(get_dense_nn, client_optimizer_fn=lambda: tf.keras.Sequential.SGD(learning_rate=client_lr), server_optimizer_fn=lambda:tf.keras.optimizers.SGD(learning_rate=server_lr))
但是,我遇到了以下错误:
AttributeError: module 'tensorflow_federated.python.learning' has no attribute 'from_keras_model'
我是不是做错了什么,还是文档有问题?
1 个回答
0
这个错误信息说明你在使用 tensorflow_federated.python.learning.from_keras_model
,但是这个接口并不存在。
在更新版本的 TensorFlow Federated 中,这个接口已经改到了 tff.learning.models.from_keras_model
。