【发布时间】:2021-01-05 11:29:34
【问题描述】:
我的问题是:如何使用 Tensorflow Federated 预测此类图像的标签?
完成模型评估后,我想预测给定图像的标签。就像在 Keras 中一样,我们这样做:
# new instance where we do not know the answer
Xnew = array([[0.89337759, 0.65864154]])
# make a prediction
ynew = model.predict_classes(Xnew)
# show the inputs and predicted outputs
print("X=%s, Predicted=%s" % (Xnew[0], ynew[0]))
输出:
X=[0.89337759 0.65864154], Predicted=[0]
以下是 state 和 model_fn 的创建方式:
def model_fn():
keras_model = create_compiled_keras_model()
return tff.learning.from_compiled_keras_model(keras_model, sample_batch)
iterative_process = tff.learning.build_federated_averaging_process(model_fn, server_optimizer_fn=lambda: tf.keras.optimizers.SGD(learning_rate=1.0),client_weight_fn=None)
state = iterative_process.initialize()
我发现这个错误:
list(self._name_to_index.keys())[:10]))
AttributeError: The tuple of length 2 does not have named field "assign_weights_to". Fields (up to first 10): ['trainable', 'non_trainable']
谢谢
【问题讨论】:
-
答案将取决于
state是如何创建的(tff.learning是否使用过?如果是,model_fn参数是如何定义的?)可以用这些细节扩展问题吗?跨度>