self-adj-dice icon indicating copy to clipboard operation
self-adj-dice copied to clipboard

Dice_coff

Open tanjia123456 opened this issue 4 years ago • 0 comments

Hello, Yours Dice_loss is for multiple classifications. If don’t want loss, just ask Dice_coff. Is the code as follows? ` def calculate_loss(logits: np.ndarray, targets: np.ndarray, alpha: float = 1.0, gamma: float = 1.0) -> float:

Dice_coff = 0.0
for curr_logits, curr_target in zip(logits, targets):
    curr_probs = softmax(curr_logits)#对logits做一个softmax

    curr_prob = curr_probs[int(curr_target)]
    prob_with_factor = ((1 - curr_prob) ** alpha) * curr_prob
    curr_coff =  (2 * prob_with_factor + gamma) / (prob_with_factor + 1 + gamma)
    Dice_coff += curr_coff

return Dice_coff / logits.shape[0]

`

tanjia123456 avatar Dec 28 '20 12:12 tanjia123456