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

[Refactor] Support passing arguments to loss from head. #523

Merged
merged 1 commit into from
Nov 10, 2021

Conversation

Ezra-Yu
Copy link
Collaborator

@Ezra-Yu Ezra-Yu commented Nov 8, 2021

Motivation

the forward function of loss(CE, Focal Loss and etc) have parameters like weight and so on. but users can not pass weight by using function head.forward_train.

Modification

Add **kwargs in heads, and add kwargs in loss function in Clshead.

BC-breaking (Optional)

No.

Use cases (Optional)

weight = torch.tensor( [0.5, 0.5] )
head.forward_train(imgs, gt_labels, weight=weight........)

Checklist

Before PR:

  • Pre-commit or other linting tools are used to fix the potential lint issues.
  • Bug fixes are fully covered by unit tests, the case that causes the bug should be added in the unit tests.
  • The modification is covered by complete unit tests. If not, please add more unit test to ensure the correctness.
  • The documentation has been modified accordingly, like docstring or example tutorials.

After PR:

  • If the modification has potential influence on downstream or other related projects, this PR should be tested with those projects, like MMDet or MMSeg.
  • CLA has been signed and all committers have signed the CLA in this PR.

@codecov
Copy link

codecov bot commented Nov 8, 2021

Codecov Report

Merging #523 (465f535) into master (dc35eb6) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #523   +/-   ##
=======================================
  Coverage   79.48%   79.48%           
=======================================
  Files         106      106           
  Lines        5975     5975           
  Branches      968      968           
=======================================
  Hits         4749     4749           
  Misses       1095     1095           
  Partials      131      131           
Flag Coverage Δ
unittests 79.48% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
mmcls/models/heads/cls_head.py 83.33% <100.00%> (ø)
mmcls/models/heads/linear_head.py 85.18% <100.00%> (ø)
mmcls/models/heads/multi_label_head.py 71.05% <100.00%> (ø)
mmcls/models/heads/multi_label_linear_head.py 67.85% <100.00%> (ø)
mmcls/models/heads/stacked_head.py 97.10% <100.00%> (ø)
mmcls/models/heads/vision_transformer_head.py 93.18% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update dc35eb6...465f535. Read the comment docs.

@Ezra-Yu Ezra-Yu requested a review from mzr1996 November 9, 2021 02:39
Copy link
Member

@mzr1996 mzr1996 left a comment

Choose a reason for hiding this comment

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

LGTM

@mzr1996 mzr1996 changed the title Add kwargs in heads [Refactor] Support passing arguments to loss from head. Nov 10, 2021
@mzr1996 mzr1996 merged commit 34d5a25 into open-mmlab:master Nov 10, 2021
@Ezra-Yu Ezra-Yu deleted the kwargs-heads branch July 18, 2022 08:45
mzr1996 pushed a commit to mzr1996/mmpretrain that referenced this pull request Nov 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants