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

[Improvement] Support soft label for CrossEntropyLoss #625

Merged
merged 13 commits into from
Feb 24, 2021

Conversation

irvingzhang0512
Copy link
Contributor

@irvingzhang0512 irvingzhang0512 commented Feb 22, 2021

Motivation

Soft labels are required for data augmentation methods like mixup, cutmix, etc. For now, official CrossEntropyLoss doesn't support soft labels.

Details

  • If number of classes is 4.
    • Hard labels example: [0, 1, 2]
    • Corresponding soft labels are [[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0]]
    • Mixup/Cutmix may create soft labels like [[0.8, 0.2, 0, 0], [0.1, 0.9, 0, 0], [0, 0, 0.6, 0.4]]
  • It's difficult to get a proper name for this pr and related args.
    • Sparse is borrowed from TensorFlow and MXNet, TensorFlow has CategoricalCrossentropy(accept non-sparse, one-hot like labels) and SparseCategorialCrossentropy(just like CrossEntropyLoss in pytorch).
    • BTW, one-hot like labels is more clear and meaningful for me.
  • For now, this pr detects loss type by the shape of label.

TODO

  • Modify CrossEntropyLoss in mmaction/models/losses/cross_entropy_loss.py.
  • unittest
  • changelog.

@codecov
Copy link

codecov bot commented Feb 22, 2021

Codecov Report

Merging #625 (ed7dda2) into master (80a9ae1) will increase coverage by 0.01%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #625      +/-   ##
==========================================
+ Coverage   84.62%   84.63%   +0.01%     
==========================================
  Files         127      127              
  Lines        8948     8958      +10     
  Branches     1503     1506       +3     
==========================================
+ Hits         7572     7582      +10     
  Misses       1020     1020              
  Partials      356      356              
Flag Coverage Δ
unittests 84.62% <100.00%> (+0.01%) ⬆️

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

Impacted Files Coverage Δ
mmaction/models/losses/cross_entropy_loss.py 100.00% <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 80a9ae1...ca2bb88. Read the comment docs.

@irvingzhang0512 irvingzhang0512 changed the title [Improvement] Support non-sparse(one-hot like) label for CrossEntropyLoss [Improvement] Support soft label for CrossEntropyLoss Feb 22, 2021
@innerlee
Copy link
Contributor

Some minor comments.

@innerlee innerlee requested a review from dreamerlin February 24, 2021 02:19
@kennymckormick
Copy link
Member

Thanks for the PR~ Besides have u find some settings in which soft labels work in action recognition? I have tried to find one but failed. If you find such a setting, you can add the config file which uses soft label for training and achieves better results.

@innerlee innerlee merged commit 1963eb4 into open-mmlab:master Feb 24, 2021
@irvingzhang0512
Copy link
Contributor Author

Thanks for the PR~ Besides have u find some settings in which soft labels work in action recognition? I have tried to find one but failed. If you find such a setting, you can add the config file which uses soft label for training and achieves better results.

I plan to implement mixup/cutmix in two weeks, which use soft label.
image

@irvingzhang0512 irvingzhang0512 deleted the non-sparse-label branch February 24, 2021 03:16
@dreamerlin dreamerlin mentioned this pull request Feb 25, 2021
9 tasks
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.

3 participants