在 Keras 中使用 tf.metrics.mean_per_class_accuracy
Use tf.metrics.mean_per_class_accuracy in Keras
我正在尝试找到一种使用 tf.metrics.mean_per_class_accuracy
作为 Keras 指标的方法。
我的 类 是二进制的,我要执行的指标是:
this one。所以它完全对应于 TF.
中的 mean_per_class accuracy
我实际上可以编写代码,但我不掌握 tensorflow 张量
binary_accuracy
和 categorical_accuracy
在 keras 中并没有精确地执行我想要的指标。
非常感谢
您可以使用以下功能:
def mean_per_class_acc(y_true, y_pred):
score, up_opt = tf.metrics.mean_per_class_accuracy(y_true, y_pred, num_classes=4)
K.get_session().run(tf.local_variables_initializer())
with tf.control_dependencies([up_opt]):
score = tf.identity(score)
return score
在您的模型中将其用作:
model.compile(loss= loss, optimizer=optimizer, metrics=[mean_per_class_acc])
我正在尝试找到一种使用 tf.metrics.mean_per_class_accuracy
作为 Keras 指标的方法。
我的 类 是二进制的,我要执行的指标是: this one。所以它完全对应于 TF.
中的mean_per_class accuracy
我实际上可以编写代码,但我不掌握 tensorflow 张量
binary_accuracy
和 categorical_accuracy
在 keras 中并没有精确地执行我想要的指标。
非常感谢
您可以使用以下功能:
def mean_per_class_acc(y_true, y_pred):
score, up_opt = tf.metrics.mean_per_class_accuracy(y_true, y_pred, num_classes=4)
K.get_session().run(tf.local_variables_initializer())
with tf.control_dependencies([up_opt]):
score = tf.identity(score)
return score
在您的模型中将其用作:
model.compile(loss= loss, optimizer=optimizer, metrics=[mean_per_class_acc])