All problems
Normalized Focal Loss
Problem
Compute focal loss over a probability map normalized by the number of positives.
Sum -((1 - p_t)^gamma) * log(p_t) over all pixels, where p_t is prob for target 1 and 1 - prob otherwise, clamping p_t to at least 1e-12. Divide by max(1, num_positives) and round to 4 decimal places.
Test cases
case 1
in: [[[0.9,0.1]],[[1,0]],2,1]
expected: 0.0021
case 2
in: [[[0.5]],[[1]],0,2]
expected: 0.3466
case 3
in: [[[0.5]],[[1]],0,0]
expected: 0.6931
Starter codePython
def normalized_focal_loss(prob, target, gamma, num_positives):
# Your code here
pass3 test cases · run your code against them in the editor