adapter new type promotion rule for Paddle 2.6 (#3108)

pull/3111/head
zxcd 2024-03-12 20:32:51 +08:00 committed by GitHub
parent a39351537d
commit 67c6517b02
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 4 additions and 3 deletions

View File

@ -9,7 +9,7 @@ def ratio2weight(targets, ratio):
weights = paddle.exp(neg_weights + pos_weights)
# for RAP dataloader, targets element may be 2, with or without smooth, some element must great than 1
weights = weights - weights * (targets > 1)
weights = weights - weights * (targets > 1).astype(weights.dtype)
return weights
@ -104,8 +104,9 @@ class MultiLabelAsymmetricLoss(nn.Layer):
# Asymmetric Focusing
if self.disable_focal_loss_grad:
paddle.set_grad_enabled(False)
asymmetric_weight = (1 - pt).pow(
self.gamma_pos * target + self.gamma_neg * (1 - target))
asymmetric_weight = (
1 - pt
).pow(self.gamma_pos * target + self.gamma_neg * (1 - target))
if self.disable_focal_loss_grad:
paddle.set_grad_enabled(True)