Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add 2 weight functions in multi-label #2952

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from

Conversation

thsno02
Copy link

@thsno02 thsno02 commented Sep 4, 2023

根据 #2951 新增两个 ratio2weight 函数。代码里延续论文中的命名,所以原 ratios2weight 改为 ratios2weight_1

Type 3 示例:

# loss function config for traing/eval process
Loss:
  Train:
    - MultiLabelLoss:
        weight: 1.0
        weight_type: 3 
        weight_alpha: 1 # float
        weight_ratio: True
        size_sum: True
  Eval:
    - MultiLabelLoss:
        weight: 1.0
        weight_type: 3 
        weight_alpha: 1 # float
        weight_ratio: True
        size_sum: True

Type 2/1 示例:

# loss function config for traing/eval process
Loss:
  Train:
    - MultiLabelLoss:
        weight: 1.0
        weight_type: 2 
        weight_ratio: True
        size_sum: True
  Eval:
    - MultiLabelLoss:
        weight: 1.0
        weight_type: 2
        weight_ratio: True
        size_sum: True

但是 https://github.com/PaddlePaddle/PaddleClas/blob/release/2.5/ppcls/loss/dmlloss.py 中 import 了 ratio2weight 这个函数,目前的解决方案是在 dmlloss 中开启 weight_type 和 weight_alpha 这两个参数,与 multilabelloss 中保持一致,然后计算对应的 loss。

@paddle-bot
Copy link

paddle-bot bot commented Sep 4, 2023

Thanks for your contribution!

@thsno02 thsno02 closed this Sep 13, 2023
@thsno02 thsno02 reopened this Sep 13, 2023
@@ -3,7 +3,14 @@
import paddle.nn.functional as F


def ratio2weight(targets, ratio):
def ratio2weight_1(targets, ratio):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里的1、2、3是官方repo的命名方式吗?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/valencebond/Rethinking_of_PAR/blob/master/tools/function.py 官方 repo 只有一个,命名中无后缀。1、2、3 是按论文给的顺序给出来的。

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

建议这里只定义一个函数ratio2weight,里边增加参数mode,mode可以是1,2,3,在注释中说明下区别

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants