title: Accuracy calculation in multilabel classification
body: <p>I'm using tensorflow on MSCOCO dataset which has 80 different classes and each image can contain more than one class (multilabels), this is modeled in my input as a list of 80 elements for each image, containing 1s at the right classes and 0s at he wrong classes.</p>
  
  <p>I'm trying to calculate accuracy by checking the number of 1s in the predicted logits layer and comparing it element wise with the input true labels.</p>
  
  <p>Using <code>tf.equal(logits , truelabels)</code> is not applicable because there are 80 classes with lots of zeros that are predicted correctly. So I end up with a high accuracy number and wrong predictions.</p>
  
  <p>I tried to use <code>tf.map_fn</code> to break down the tensor into elements but apparently I can't use a counter like variable inside the function to choose the current true labels from a the true label batch (<code>Y_</code>).</p>
  
  <p>here is my code:</p>
  
  <pre><code>rounded = tf.round(Y)
  C = 0
  V = 0
  sumseen = 0.
  sumtrue = 0.
  avgg = 0.
  
  def avgfunc(elm):
    global C
    global V
    global sumseen
    global sumtrue
    global avgg
    tru = Y_[C]
    ***tf.add(V,1)***
    cond1 = tf.count_nonzero(tf.cast(tf.equal(elm,tf.constant(1.,tf.float32)),tf.float32))
    cond2 = tf.count_nonzero(tf.cast(tf.equal(elm,tru[V]),tf.float32))
    if(cond1 == 1):
        sumseen+=1
        if(cond2 == 1):
            sumtrue+=1
    ***if(V &gt;= 79):
        V = 0
        avgg = ((sumtrue/sumseen)*100) if sumseen !=0 else 0***
    return sumseen
  
  def _comparefunc(elem_probs):
    global C
    tru = Y_[C]
    mapout = tf.map_fn(avgfunc, elem_probs)
    ***C = C+1
    if(C == 49):
        C = 0***
    return avgg
  
  outputafter = tf.map_fn(_comparefunc, rounded)
  accuracyofbatch = tf.reduce_mean(outputafter)
  </code></pre>