```
_,loss_idx = loss_c.sort(1, descending=True)
_,idx_rank = loss_idx.sort(1)
````
Just wondering, is this a bug? I don't think you should put descending=True to find idx_rank.
No, so basically what's going on here is we take the indices that the descending sorted values held before they were sorted and
tensor a = [20,10,80,40,70,30,]
lets say after removing positive index values(setting pos. vals to 0) it's now:
tensor a = [20,10,0,40,0,30]
_, loss_idx = a.sort(1, descending=True) # --> disregard [40,30,20,10,0,0]
--> loss_idx is now [3,5,0,1,2,4]
_, idx_rank = [3,5,0,1,2,4] .sort(1) # --> disregard [0,1,2,3,4,5] --> idx_rank is now [2,3,4,0,5,1]
Comparing idx_rank with tensor a we see that idx_rank is simply the rank assigned to each corresponding value in tensor a with the highest ranking value being the highest valued negative (Hence hard negative mining). The reason we sort with descending=True is because we want to sort in terms of our confidence of the negative instances' losses.
Hi,
I was wondering why you need to compare the posIdx and negIdx to 0 when filtering the predictions / targets:
(pos_idx+neg_idx).gt(0)
Most helpful comment
No, so basically what's going on here is we take the indices that the descending sorted values held before they were sorted and
tensor a = [20,10,80,40,70,30,]
lets say after removing positive index values(setting pos. vals to 0) it's now:
tensor a = [20,10,0,40,0,30]
_, loss_idx = a.sort(1, descending=True) # --> disregard [40,30,20,10,0,0]
--> loss_idx is now [3,5,0,1,2,4]
_, idx_rank = [3,5,0,1,2,4] .sort(1) # --> disregard [0,1,2,3,4,5] --> idx_rank is now [2,3,4,0,5,1]
Comparing idx_rank with tensor a we see that idx_rank is simply the rank assigned to each corresponding value in tensor a with the highest ranking value being the highest valued negative (Hence hard negative mining). The reason we sort with descending=True is because we want to sort in terms of our confidence of the negative instances' losses.