title: How to calculate top-k in-class accuracies using TensorFlow Slim metrics
body: <p>I'd like to extend <a href="https://github.com/tensorflow/models/blob/master/research/slim/eval_image_classifier.py" rel="nofollow noreferrer">this script</a> such that it is able to evaluate the top-k accuracies per class. I hope it boils down to adding a metric to the following code snippet:</p>
  
  <pre><code># Define the metrics:
  names_to_values, names_to_updates = slim.metrics.aggregate_metric_map({
      'Accuracy': slim.metrics.streaming_accuracy(predictions, labels),
      'Recall_5': slim.metrics.streaming_recall_at_k(
          logits, labels, 5), })
  </code></pre>
  
  <p>I already followed <a href="https://github.com/tensorflow/models/issues/1286#issuecomment-317205632" rel="nofollow noreferrer">this comment</a> to add the confusion matrix, which allows me to calculate the top1 in-class accuracies. However, I'm not sure how to get the top-k values as I can't find an appropriate slim metric.</p>
  
  <p>To clarify:</p>
  
  <ul>
  <li>I'm not looking for the average top-k accuracy, but the per class values.</li>
  <li>I'm able to implement the required calculations using basic tensors, but I'm new to the slim interface and don't know how to do it using the above script.</li>
  </ul>