Tensorflow 训练精度显示为0.0

Tensorflow 训练精度显示为0.0,tensorflow,Tensorflow,我的代码: 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

我的代码:

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。 然而,情况不应该如此。
我不明白,代码出了什么问题。我在博客网站上看到了计算准确度的代码,只有准确度函数代码,原因可能是pred_标签不是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=AccuracyGits,feed\u labels中,我将logits作为参数传递,这是错误的!您需要在pred_标签中传递预测标签,而不是logits。变量名不是随机选择的。pred_labels=tf.argmaxlogits,1将完成此任务,对吗?注释不是stackoverflow中的聊天。但你的方法是另一种方法。所以是的,用你们的方法,我只得到了30%,10%和0.0%的准确度。我反复得到这些值