本文介绍了似乎无法使Tensorflow的tf.metrics.auc工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Tensorflow具有计算AUC的功能:tf.metrics.auc().这是我尝试计算auc的代码的一部分:

Tensorflow has a function to calculate AUC: tf.metrics.auc(). Here is my a section of my code trying to compute auc:

init = tf.global_variables_initializer()

with tf.Session() as sess:
    sess.run(init)

    for epoch in range(training_epochs):
        sess.run(optimizer, feed_dict = {x : x_train, y : y_train, p_keep_input: 0.8, p_keep_hidden: 0.5})
        avg_cost = sess.run(cost, feed_dict = {x : x_train, y : y_train, p_keep_input: 0.8, p_keep_hidden: 0.5})

        if epoch % display_step == 0:
            training_acc = accuracy.eval({x : x_train, y : y_train, p_keep_input: 1.0, p_keep_hidden: 1.0})
            print("Epoch:", '%03d' % (epoch), "Training Accuracy:", '%.5f' % (training_acc), "cost=", "{:.5f}".format(avg_cost))

    print("Optimization Done!")


    roc_score = tf.metrics.auc(y, pred)
    roc_score = tf.convert_to_tensor(roc_score)
    print(roc_score.eval({x : x_test, y : y_test, p_keep_input: 1.0, p_keep_hidden: 1.0}))

我得到的错误的任何部分都在下面.整个错误相当漫长.

Any section of the error I get is below. The entire error is quite lengthy.

FailedPreconditionError (see above for traceback): Attempting to use uninitialized value auc_4/false_positives
     [[Node: auc_4/false_positives/read = Identity[T=DT_FLOAT, _class=["loc:@auc_4/false_positives"], _device="/job:localhost/replica:0/task:0/cpu:0"](auc_4/false_positives)]]

我希望您能找到解决此问题的任何指示.谢谢

I'd appreciate any pointers on how to resolve this. Thanks

推荐答案

现在可能为时已晚,但如果尚未找到解决方案,请尝试以下更改:

might be too late now but if you haven't found the solution, try this change:

sess.run(tf.global_variables_initializer())
sess.run(tf.local_variables_initializer())
_,roc_score = tf.metrics.auc(y, pred)
print(sess.run(roc_score, feed_dict={x : x_test, y : y_test, p_keep_input: 1.0, p_keep_hidden: 1.0}))

这篇关于似乎无法使Tensorflow的tf.metrics.auc工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-19 17:53