如何获得正确的多标签预测准确性? [英] How to get correct acccuracy for multi label prediction?

查看:654
本文介绍了如何获得正确的多标签预测准确性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试获得一个进行多标签预测的张量流网络.将softmax与一键(单个标签)预测一起使用可以正常工作.准确地计算出准确度,网络可以按需学习.

I am trying to get a tensorflow network that does multi-label predictions. Using softmax with one-hot (single label) predictions works correctly. The accuracy get's calculated perfectly and the network learns as it should.

我的基本网络设置是:

X = tf.placeholder(features.dtype, (None, 300), name="input")
y = tf.placeholder(hots.dtype, (None,64), name="labels")    

with tf.name_scope("dnn"):
    hidden1 = fully_connected(X, 900, scope="hidden1")
    hidden2 = fully_connected(hidden1, 450, scope="hidden2")
    hidden3 = fully_connected(hidden2, 225, scope="hidden3")
    logits = fully_connected(hidden3, max, scope="outputs", activation_fn=None)

with tf.name_scope("loss"):
    xentropy = tf.nn.softmax_cross_entropy_with_logits(labels=y, logits=logits)
    loss = tf.reduce_mean(xentropy, name="loss")

learning_rate = 0.05

with tf.name_scope("train"):
    optimizer = tf.train.GradientDescentOptimizer(learning_rate)
    training_op = optimizer.minimize(loss)

with tf.name_scope("eval"):
    correct = tf.nn.in_top_k(logits, tf.argmax(y,1), 1)
    accuracy = tf.reduce_mean(tf.cast(correct, tf.float32))

由于目标是获得多标签预测,因此我更改了损失和准确性:(基于

Because the goal is to get multi-label predictions, I changed the loss and the accuracy: (based on Tensorflow, multi label accuracy calculation)

with tf.name_scope("loss"):
    xentropy = tf.nn.sigmoid_cross_entropy_with_logits(labels=tf.cast(y, tf.float32), logits=logits)
    loss = tf.reduce_mean(xentropy, name="loss")

with tf.name_scope("eval"): 
    correct_prediction = tf.equal(tf.round(tf.nn.sigmoid(logits)), tf.round(tf.cast(y, tf.float32)))
    accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))

但是,这导致每个时期的精度为Train accuracy: 0.984375 Test accuracy: 0.984375(带有单个标签的一热点"数据).它没有改变,始终是这个数字.

However, this results in a accuracy of Train accuracy: 0.984375 Test accuracy: 0.984375 for each epoch (with the single label one-hot data). It doesn't change, it's always this number.

我对多标签进行了很多准确度计算,但是找不到真正能给我正确结果的方法.我在这里想念什么?

I tested with a lot of accuracy calculations for multi-label, but can't find one that actually does give me proper results. What am I missing here?

推荐答案

最后,经过无数次尝试修复此问题之后,事实证明,除了优化程序之外,其他一切都还可以.当使用AdamOptimizer()代替GradientDescentOptimizer(learning_rate)时,网络开始快速学习,在40个周期内从0.7到0.97的精度.

At the end, after countless tries to get this fixed, it turned out that everything was ok, except for the optimizer. When using the AdamOptimizer() instead of the GradientDescentOptimizer(learning_rate) the network started learning fast, from 0.7 to 0.97 accuracy in 40 epochs.

也许对学习率的一些调整也可以使它起作用,但是现在这终于解决了!

Maybe some tweaking of the learning rate would also make it work, but for now this is finally solved!

这篇关于如何获得正确的多标签预测准确性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆