【问题标题】:Training accuracy showing 0.0训练准确率显示 0.0
【发布时间】:2018-03-24 17:53:02
【问题描述】:

我的代码:

def accuracy(pred_labels,true_labels):
    true_labels = tf.cast(tf.reshape(true_labels,[-1,1]),tf.float32)
    correct_pred = tf.equal(pred_labels,true_labels)
    accuracy = tf.reduce_mean(tf.cast(correct_pred,tf.float32))
    return accuracy

当我跑步时:

feed_images = tf.placeholder(tf.float32,shape=(None,96,96,3))
feed_labels = tf.placeholder(tf.float32,shape=(None,))
logits = nn_model(feed_images)
cost = loss(logits,feed_labels)
opt_adam = optimizer(cost)
acc = accuracy(logits,feed_labels)
feed_trdict={feed_images:ni,feed_labels:nl}
tr_acc = sess.run(acc,feed_dict = feed_trdict)

我得到所有连续迭代的训练精度为 0.0。 然而不应该如此。 我不明白,代码有什么问题。我在一个博客网站上看到了计算准确率的代码(只有accuracy函数代码)

【问题讨论】:

    标签: tensorflow


    【解决方案1】:

    原因(可能)是pred_labels不是logits。尝试一些类似的东西

    correct = tf.cast(tf.nn.in_top_k(logits, true_labels, 1), tf.float32, name='correct')
    accuracy = tf.reduce_mean(correct, name='accuracy')
    

    可能会有帮助。

    我不明白,为什么问题不包含 MWE 一些示例数据来重现这种效果。否则,我们只能用水晶球来猜测造成这种影响的原因。

    【讨论】:

    • 但在这一行 acc = accuracy(logits,feed_labels) 我将 logits 作为参数传递
    • this 是错误的!您需要在 pred_labels 中传递预测标签,而不是 logits。变量名不是随机选择的。
    • pred_labels = tf.argmax(logits,1) 会完成这项工作,对吧?
    • 评论不是stackoverflow中的聊天。但是您的方法是另一种方法。所以是的。
    • 使用您的方法,我只能获得 30%、10% 和 0.0% 值的准确度。我反复得到这些值
    猜你喜欢
    • 1970-01-01
    • 2017-10-05
    • 2023-03-17
    • 2021-10-13
    • 2020-04-07
    • 1970-01-01
    • 2018-12-26
    • 2018-09-18
    • 2018-12-20
    相关资源
    最近更新 更多