self-adj-dice
self-adj-dice copied to clipboard
Dice_coff
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]
`