Hi there,
Could someone please point me in the correct direction and the Functional method to use when trying to find the top K indices? Something like an argsort? I want to find the top 4 elements by size and their indices from a FunctionalTensor.
Hi there,
Could someone please point me in the correct direction and the Functional method to use when trying to find the top K indices? Something like an argsort? I want to find the top 4 elements by size and their indices from a FunctionalTensor.
Did you look at Functional.TopK?
It sounds like it might be what you are looking for.
I’ve already tried that, it returns the Top K elements and not the indices, there’s no way to find out their indices if I’m not mistaken.
The return value of Functional.TopK is an array of FunctionalTensors. The first entry is the output values and the second is the indices.
Got it, thanks!
Hi, even after multiple attempts to try and get the TopK to work for the BlazeHands, I couldn’t figure it out because it’s very difficult to debug the code, could someone please help out?
This is the original function ion the BlazeUtils.cs file for BlazeHands:
public static (FunctionalTensor, FunctionalTensor, FunctionalTensor) ArgMaxFiltering(FunctionalTensor rawBoxes, FunctionalTensor rawScores)
{
var detectionScores = ScoreFiltering(rawScores, 100f); // (1, 2016, 1)
var bestScoreIndex = Functional.ArgMax(rawScores, 1).Squeeze();
var selectedBoxes = Functional.IndexSelect(rawBoxes, 1, bestScoreIndex).Unsqueeze(0); // (1, 1, 16)
var selectedScores = Functional.IndexSelect(detectionScores, 1, bestScoreIndex).Unsqueeze(0); // (1, 1, 1)
return (bestScoreIndex, selectedScores, selectedBoxes);
}
I am trying to get the top 2 scores instead of only the best one, here’s what my function looks like:
public static (FunctionalTensor, FunctionalTensor, FunctionalTensor) ArgMaxFiltering(FunctionalTensor rawBoxes, FunctionalTensor rawScores)
{
var detectionScores = ScoreFiltering(rawScores, 100f); // (1, 2016, 1)
// Use TopK to get the top two scores
var topTwoScoreIndexes = Functional.TopK(detectionScores, 1, 1);
// Select the top two boxes and top two scores
var bestBox1 = Functional.IndexSelect(rawBoxes, 1, topTwoScoreIndexes[0][1].Squeeze()).Unsqueeze(0);
var bestScore1 = Functional.IndexSelect(detectionScores, 1, topTwoScoreIndexes[0][0].Squeeze()).Unsqueeze(0);
var bestBox2 = Functional.IndexSelect(rawBoxes, 1, topTwoScoreIndexes[1][1].Squeeze()).Unsqueeze(0);
var bestScore2 = Functional.IndexSelect(detectionScores, 1, topTwoScoreIndexes[1][0].Squeeze()).Unsqueeze(0);
Debug.Log(bestBox1);
............
}
Even after trying a lot of modifications, I keep getting errors regarding FunctionalTensor has incorrect type.
Cheers.
The TopK returns an array with two tensors, the first is the scores, the second is the indices. That means ‘topTwoScoreIndexes[0]’ is a float tensor consisting of scores, you don’t need to index the scores tensor with this again. Lines 9 and 10 look wrong because you are trying to index with a float tensor (of scores). Lines 10 and 12 look unnecessary because the scores are already returned from the TopK method as the first tensor.
Hope that clears things up.