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

use torch.nn.functional.one_hot rewrite convert_to_one_hot #696

Merged
merged 9 commits into from
Feb 28, 2022

Conversation

HuDi2018
Copy link
Contributor

@HuDi2018 HuDi2018 commented Feb 16, 2022

Thanks for your contribution and we appreciate it a lot. The following instructions would make your pull request more healthy and more easily get feedback. If you do not understand some items, don't worry, just make the pull request and seek help from maintainers.

Motivation

Torch has the implementation of one-hot, here we can replace the one-hot implemented by MMCLS itself

Modification

as described above

BC-breaking (Optional)

Does the modification introduce changes that break the backward compatibility of the downstream repositories?
If so, please describe how it breaks the compatibility and how the downstream projects should modify their code to keep compatibility with this PR.

Use cases (Optional)

If this PR introduces a new feature, it is better to list some use cases here and update the documentation.

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.

@CLAassistant
Copy link

CLAassistant commented Feb 16, 2022

CLA assistant check
All committers have signed the CLA.

@Ezra-Yu
Copy link
Collaborator

Ezra-Yu commented Feb 17, 2022

Thank you for your contribution, please fix the lint refer to this guide before we review it.

@Ezra-Yu
Copy link
Collaborator

Ezra-Yu commented Feb 17, 2022

After installing pre-commit, the pre-commit does not work until you create a commit,

try to run

pre-commit run --all-files

twice in '$MMClassification' to check if there is any style error and fix it.

@HuDi2018
Copy link
Contributor Author

cannot understand this error:

yapf.....................................................................Failed
- hook id: yapf
- files were modified by this hook

@Ezra-Yu

@codecov
Copy link

codecov bot commented Feb 17, 2022

Codecov Report

Merging #696 (68f1542) into dev (43024cd) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##              dev     #696   +/-   ##
=======================================
  Coverage   85.03%   85.03%           
=======================================
  Files         121      121           
  Lines        7389     7392    +3     
  Branches     1277     1278    +1     
=======================================
+ Hits         6283     6286    +3     
  Misses        916      916           
  Partials      190      190           
Flag Coverage Δ
unittests 85.03% <100.00%> (+<0.01%) ⬆️

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

Impacted Files Coverage Δ
mmcls/models/losses/utils.py 56.25% <100.00%> (-1.33%) ⬇️
mmcls/models/backbones/resnet.py 100.00% <0.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 43024cd...68f1542. Read the comment docs.

@Ezra-Yu
Copy link
Collaborator

Ezra-Yu commented Feb 17, 2022

That means the pre-commit would modify the code automatically.

you can let the L117 in one line:

    one_hot_targets = F.one_hot(targets.long().squeeze(-1), num_classes=classes)

and run pre-commit run --all-files twice in command, the pre-commit would modify this line automatically.
it would be:

    one_hot_targets = F.one_hot(
        targets.long().squeeze(-1), num_classes=classes)

@HuDi2018
Copy link
Contributor Author

That means the pre-commit would modify the code automatically.

you can let the L117 in one line:

    one_hot_targets = F.one_hot(targets.long().squeeze(-1), num_classes=classes)

and run pre-commit run --all-files twice in command, the pre-commit would modify this line automatically. it would be:

    one_hot_targets = F.one_hot(
        targets.long().squeeze(-1), num_classes=classes)

doesn't seem like a necessary change, currently I cannot install&use pre-commit successfully for some permission problem, so is there a work-around?

@Ezra-Yu
Copy link
Collaborator

Ezra-Yu commented Feb 17, 2022

me permission problem, s

OK, get it. We would modify it later when reviewing.

@HuDi2018
Copy link
Contributor Author

me permission problem, s

OK, get it. We would modify it later when reviewing.

that's great help

@Ezra-Yu Ezra-Yu self-requested a review February 17, 2022 03:50
@Ezra-Yu Ezra-Yu changed the base branch from master to dev February 18, 2022 10:33
Copy link
Collaborator

@Ezra-Yu Ezra-Yu 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 merged commit 1214df0 into open-mmlab:dev Feb 28, 2022
mzr1996 pushed a commit to mzr1996/mmpretrain that referenced this pull request Nov 24, 2022
…_hot`. (open-mmlab#696)

* some change to mmcls/models/losses/utils.py:convert_to_one_hot()

* fixed problem: line too long

* fixed wrong output shape

* fixed lint PEP8 E128

* fix lint

* fix lint

* add unit tests

Co-authored-by: Ezra-Yu <[email protected]>
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.

4 participants