Can't seem to get Tensorflow's tf.metrics.auc working

拈花ヽ惹草 提交于 2019-12-11 03:44:36

问题


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


回答1:


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}))


来源:https://stackoverflow.com/questions/42632656/cant-seem-to-get-tensorflows-tf-metrics-auc-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!