From 67c6517b022966ed4f352fd2edde4fe3e60b23a3 Mon Sep 17 00:00:00 2001 From: zxcd <228587199@qq.com> Date: Tue, 12 Mar 2024 20:32:51 +0800 Subject: [PATCH] adapter new type promotion rule for Paddle 2.6 (#3108) --- ppcls/loss/multilabelloss.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/ppcls/loss/multilabelloss.py b/ppcls/loss/multilabelloss.py index c1b3d42b8..51b5f7c81 100644 --- a/ppcls/loss/multilabelloss.py +++ b/ppcls/loss/multilabelloss.py @@ -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)