Search code examples
tensorflowargmax

Tensorflow for argmax of top 5?


tf.argmax return the top 1 of a tensor. I did some research and did not find a good way (other than scan) to get top 5 of a tensor. Please let me know if you have a better approach. Thanks!


Solution

  • You can use tf.nn.top_k as found in the documentation here.

    tf.nn.top_k(input, k=5, sorted=True, name=None)
    

    For your case, k=5, as shown above.