tf.argmax() 对于多个索引 Tensorflow

tf.argmax() for more than one index Tensorflow

在 Tensorflow 中,tf.argmax() returns 数组中最大元素的索引。

但是,对于多标签分类任务,returns数组中最大的N个元素的函数会非常好用。

predicted_array: [0.4, 0.6, 0.7, 0.2, 0.9]
tf.something(predicted_array, N = 2): [2,4]

然后将其与 ground truth 一个热编码数组进行比较

one_hot_array: [0, 0, 1, 0, 1]
tf.something(one_hot_array, N = 2): [2,4]

有这样的功能吗?或者类似的东西?

感谢您的帮助

是的,有。它是 tf.nn.top_k(来自 here)。

您可以将其用作 tf.nn.top_k(predicted_array, k=2)