【发布时间】:2021-05-29 19:45:36
【问题描述】:
我正在使用本教程尝试通过 TensorFlow 的教程了解联合模型的工作原理:https://colab.research.google.com/github/tensorflow/federated/blob/master/docs/tutorials/federated_learning_for_image_classification.ipynb
目前,模型是这样定义的,它使用准确度作为指标。
def model_fn():
keras_model = create_keras_model()
return tff.learning.from_keras_model(
keras_model,
input_spec = preprocessed_example_dataset.element_spec,
loss = tf.keras.losses.SparseCategoricalCrossentropy(),
metrics = [tf.keras.metrics.SparseTopKCategoricalAccuracy()]
)
我想使用精确率和召回率作为指标,或者在训练模型后找到它们,但我不知道该怎么做。
我尝试为 metrics = [tf.keras.metrics.SparseTopKCategoricalAccuracy(), tf.keras.metrics.Precision()] 之类的指标添加精度并运行此代码,但它给了我一个错误。
iterative_process = tff.learning.build_federated_averaging_process(
model_fn,
client_optimizer_fn = lambda: tf.keras.optimizers.SGD(learning_rate=0.01),
server_optimizer_fn = lambda: tf.keras.optimizers.SGD(learning_rate=1.5))
错误输出:
ValueError Traceback (most recent call last)
<ipython-input-13-f8ac3534e325> in <module>()
2 model_fn,
3 client_optimizer_fn = lambda: tf.keras.optimizers.SGD(learning_rate=0.01),
----> 4 server_optimizer_fn = lambda: tf.keras.optimizers.SGD(learning_rate=1.5))
ValueError: Shapes (None, 10) and (None, 1) are incompatible
之前,我曾针对常规 centralized model here 提出过类似的问题,但我认为我不能使用相同的方法,因为您无法以与我相同的方式返回预测结果成立。 我还尝试查看其他文档such as this,但它也使用准确性作为指标,所以这没有帮助。如何获得这个联合模型的准确率和召回率?
【问题讨论】:
标签: python tensorflow keras