Реализация top_k для Eigen в С++ ⇐ C++
-
Anonymous
Реализация top_k для Eigen в С++
I have a 3D Eigen tensor (Eigen::Tensor) of shape [B, D, C] containing floating point numbers that represent the confidence score of some network output.
I want to perform top k and obtain the values and indices of the highest-scoring outputs along the second dimension and reduce D to a smaller dimension k. The resulting vector should be of shape [B, k, C].
In python (tensorflow) it would simply be (in this case integers for simplicity):
data = np.array([[[3, 9, 8, 5], [3, 3, 0, 1], [5, 5, 1, 9]], [[1, 3, 0, 9], [8, 3, 7, 7], [8, 0, 9, 5]]]) values, indices = tf.math.top_k(tensor, k=2, sorted=False) And the result:
Values [[[8 9] [3 3] [5 9]] [[3 9] [7 8] [8 9]]] Indices [[[2 1] [1 0] [0 3]] [[1 3] [2 0] [0 2]]] Thanks in advance!
Источник: https://stackoverflow.com/questions/781 ... eigen-in-c
I have a 3D Eigen tensor (Eigen::Tensor) of shape [B, D, C] containing floating point numbers that represent the confidence score of some network output.
I want to perform top k and obtain the values and indices of the highest-scoring outputs along the second dimension and reduce D to a smaller dimension k. The resulting vector should be of shape [B, k, C].
In python (tensorflow) it would simply be (in this case integers for simplicity):
data = np.array([[[3, 9, 8, 5], [3, 3, 0, 1], [5, 5, 1, 9]], [[1, 3, 0, 9], [8, 3, 7, 7], [8, 0, 9, 5]]]) values, indices = tf.math.top_k(tensor, k=2, sorted=False) And the result:
Values [[[8 9] [3 3] [5 9]] [[3 9] [7 8] [8 9]]] Indices [[[2 1] [1 0] [0 3]] [[1 3] [2 0] [0 2]]] Thanks in advance!
Источник: https://stackoverflow.com/questions/781 ... eigen-in-c
Мобильная версия