Skip to content
DeepForgeby svx
All problems
MediumComputer Visioncv-195

Hard Negative Mining by Loss Ratio

Problem

Select the hardest negative examples for training.

Given negative losses, choose min(len(losses), pos_count * neg_ratio) negatives with the largest losses. Return their indices in descending loss order, breaking ties by smaller index.

Test cases

case 1
in: [[0.1,0.9,0.5,0.8],1,2]
expected: [1,3]
case 2
in: [[0.1,0.9,0.5,0.8],1,1]
expected: [1]
case 3
in: [[0.1,0.9,0.5,0.8],0,3]
expected: []
case 4
in: [[0.1,0.9,0.5,0.8],2,5]
expected: [1,3,2,0]
Starter codePython
def hard_negative_indices(neg_losses, pos_count, neg_ratio):
    # Your code here
    pass

4 test cases · run your code against them in the editor