我正在尝试为Keras实现AUC指标,以便在运行期间model.fit()运行验证集后进行AUC测量.
我将指标定义为:
def auc(y_true, y_pred):
keras.backend.get_session().run(tf.global_variables_initializer())
keras.backend.get_session().run(tf.initialize_all_variables())
keras.backend.get_session().run(tf.initialize_local_variables())
#return K.variable(value=tf.contrib.metrics.streaming_auc(
# y_pred, y_true)[0], dtype='float32')
return tf.contrib.metrics.streaming_auc(y_pred, y_true)[0]
Run Code Online (Sandbox Code Playgroud)
这导致以下错误,我不明白.
tensorflow.python.framework.errors_impl.FailedPreconditionError:
Attempting to use uninitialized value auc/true_positives...
Run Code Online (Sandbox Code Playgroud)
从在线阅读来看,似乎问题是2倍,张量流/ keras中的错误和部分问题,而tensorflow无法从推理初始化局部变量.鉴于这两个问题,我不明白为什么我会收到此错误或如何克服它.有什么建议?
我写了另外两个可以正常工作的指标:
# PFA, prob false alert for binary classifier
def binary_PFA(y_true, y_pred, threshold=K.variable(value=0.5)):
y_pred = K.cast(y_pred >= threshold, 'float32')
# N = total number of negative labels
N = K.sum(1 - y_true)
# FP = total number of false alerts, alerts from the negative class labels
FP = K.sum(y_pred - y_pred …Run Code Online (Sandbox Code Playgroud) keras ×1