将 tf 插件中的 tfa.metrics.F1Score 替换为 tf.keras.metrics.F1Score

Replace tfa.metrics.F1Score from tf addon by tf.keras.metrics.F1Score

提问人:Sime 提问时间:11/15/2023 最后编辑:desertnautSime 更新时间:11/16/2023 访问量:31

问:

我有一个旧的 Kera 模型,该模型使用 Tensorflow Addon 的 F1Score 自定义模型编译,现已弃用,我想从保存的模型迁移到 tf.keras.metrics.F1Score

这是我现在加载模型时使用的:

   custom_objects = {
            'F1Score': F1Score(num_classes=4, threshold=0.5)
   }

我试图用新功能替换它,但我收到以下消息:

ValueError: Unable to restore custom object of class "Addons>F1Score" (type _tf_keras_metric). Please make sure that this class is included in the `custom_objects` arg when calling `load_model()`. Also, check that the class implements `get_config` and `from_config`.

Complete metadata: {'class_name': 'Addons>F1Score', 'name': 'f1_score', 'dtype': 'float32', 'config': {'name': 'f1_score', 'dtype': 'float32', 'num_classes': 4, 'average': None, 'threshold': 0.5}, 'shared_object_id': 32}

我该如何迁移到新功能?

Python TensorFlow 机器学习 Keras TensorFlow2.0

评论

0赞 Innat 11/16/2023
如果将 tf-addons 替换为新的 tf-keras API,为什么会出现在日志消息中?Addons>F1Score
0赞 Sime 11/19/2023
嗨@Innat,这是因为在我的原始模型上我使用了“Addons>F1score”,所以日志告诉我,然后在我的旧模型中我使用了 Addon,所以我不能在上面使用其他类名
0赞 mhenning 11/21/2023
您能否用旧模型加载旧模型,使用新模型创建新模型,并将权重从旧模型复制到新模型?当然,这只有在您可以使用时才有效。Addons>F1ScoreF1ScoreAddons>F1Score

答: 暂无答案