Реализация top_k для Eigen в С++C++

Программы на C++. Форум разработчиков
Ответить
Anonymous
 Реализация top_k для Eigen в С++

Сообщение Anonymous »


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
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «C++»