title: Mean average precision (mAP) in tensorflow
body: <p>I need to calculate the <strong>mAP</strong> described in this <a href="https://stackoverflow.com/a/37498432/7649980">question</a> for <strong>object detection</strong> using <strong>Tensorflow</strong>.</p>
  <p><strong>Average precision(AP)</strong> is a typical performance measure used for ranked  sets. AveragePrecision is defined as the average of the precision scores after each   true  positive, TP in the scope  S. Given  a scope  S =  7,and  a  ranked list (gain vector)  G  = [1,1,0,1,1,0,0,1,1,0,1,0,0,..]
  where  1/0  indicate the gains associated to relevant/non-­‐relevant items,  respectively:</p>
  <p>AP = (1/1 + 2/2 + 3/4 + 4/5) / 4    = 0.8875.</p>
  <p><strong>Mean Average Precision (mAP)</strong>: average of the average precision value for a  set of queries.</p>
  <p>i got 5 <strong>One-Hot</strong> tensors with the predictions:</p>
  <pre><code>prediction_A 
  prediction_B
  prediction_C 
  prediction_D 
  prediction_E 
  </code></pre>
  <p>where a single prediction tensor has this structure (for example prediction_A):</p>
  <pre><code>00100
  01000
  00001
  00010
  00010
  </code></pre>
  <p>Then i've got the correct labels (one-hot) tensors, with the same structure:</p>
  <pre><code>y_A
  y_B
  y_C
  y_D
  y_E
  </code></pre>
  <p>i want compute <strong>mAP</strong> using <strong>tensorflow</strong>, cause i want summarize that, how i can do it?</p>
  <p>i found this <a href="https://www.tensorflow.org/api_docs/python/tf/contrib/metrics/streaming_sparse_average_precision_at_k" rel="nofollow noreferrer">function</a>  but i can't use it, cause i have a multidimensional vector.</p>
  <p>I also write a python function that compute <strong>AP</strong> but it doesn't use Tensorflow</p>
  <pre><code>def compute_av_precision(match_list):
      n = len(match_list)
      tp_counter = 0
  
      cumulate_precision = 0
      for i in range(0,n):
          if match_list[i] == True:
  
              tp_counter += 1
  
              cumulate_precision += (float(tp_counter)/float(i+1))
  
  
      if tp_counter != 0:
          av_precision = cumulate_precision/float(tp_counter)
          return av_precision
      return 0
  </code></pre>