Tensorflow, multi label accuracy calculation

前端 未结 2 1539
温柔的废话
温柔的废话 2021-01-30 18:23

I am working on a multi label problem and i am trying to determine the accuracy of my model.

My model:

NUM_CLASSES         


        
2条回答
  •  心在旅途
    2021-01-30 18:57

    I believe the bug in your code is in: correct_prediction = tf.equal( tf.round( pred ), tf.round( y_ ) ).

    pred should be unscaled logits (i.e. without a final sigmoid).

    Here you want to compare the output of sigmoid(pred) and y_ (both in the interval [0, 1]) so you have to write:

    correct_prediction = tf.equal(tf.round(tf.nn.sigmoid(pred)), tf.round(y_))
    

    Then to compute:

    • Mean accuracy over all labels:
    accuracy1 = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))
    
    • Accuracy where all labels need to be correct:
    all_labels_true = tf.reduce_min(tf.cast(correct_prediction), tf.float32), 1)
    accuracy2 = tf.reduce_mean(all_labels_true)
    

提交回复
热议问题