Soft Dice Loss
~12 mincode completion
Implement soft_dice_loss(probs, target, eps) returning a scalar.
Examples
A perfect hard prediction has zero loss
- Input
- soft_dice_loss([[1, 1], [0, 0]], [[1, 1], [0, 0]], 0)
- Output
- 0
Half-confident everywhere on a half-foreground target: loss 0.5
- Input
- soft_dice_loss([[0.5, 0.5]], [[1, 0]], 0)
- Output
- 0.5
Empty prediction on an empty target is zero loss because of eps
- Input
- soft_dice_loss([[0, 0]], [[0, 0]], 1)
- Output
- 0
Hints
Hint 1
Sum with , and check which axis you are summing over.
Hint 2
Watch for this: thresholded the probabilities before the sum.
Requirements
probs: array of foreground probabilities in [0, 1]target: array of 0/1 labels, same shapeeps: smoothing constant added to numerator and denominatorReturn scalar 1 - soft Dice
Constraints
Allowed library: NumPy only
Time limit: 200 ms, Memory: 64 MB
Try similar problems(4)
Where this shows up
~12 min
••••••••••••••••
8 employers weight this skill
4 autonomy companies, 1 defense company, 1 health and bio company, 1 enterprise vendor, 1 AI product company. Top match scores 81.
Python
import numpy as np
def soft_dice_loss(probs, target, eps):
"""
Soft Dice loss on a single-class probability map.
Args:
probs: array of foreground probabilities in [0, 1]
target: array of 0/1 labels, same shape
eps: smoothing constant added to numerator and denominator
Returns:
scalar 1 - soft Dice
"""
# YOUR CODE HERE
pass