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

Fix potential bugs in accuracy.py #1496

Merged
merged 1 commit into from
Apr 21, 2022
Merged

Conversation

Johnson-Wang
Copy link
Contributor

@Johnson-Wang Johnson-Wang commented Apr 21, 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

There is a potential bug in accuracy.py, and This PR aims to fix this issue.
In line

correct = correct[:, target != ignore_index]
, correct = correct[:, target != ignore_index] is used to filter out the ignored targets. However, as the default value of ignore_index is None, this line would cause unwanted behavior. For example

>>> target = torch.ones(3)
>>> target != 255
tensor([True,  True, True])
>>> target != None
True
>>> target[target != 255].shape
torch.Size([3])
>>> target[target != None].shape
torch.Size([1, 3])

Therefore an unwanted additional dimension is created in the original implementation. Luckily, the correct tensor is finally flattened and the above behavior would not affect the final results. However, this is still a potential bug, and a quick fix would be better.

Modification

I used an if else condition to cater for the case of ignored_index is None.

Checklist

  • Pre-commit or other linting tools are used to fix the potential lint issues.
  • The modification is covered by complete unit tests. If not, please add more unit test to ensure the correctness.
  • If the modification has potential influence on downstream projects, this PR should be tested with downstream projects, like MMDet or MMDet3D.
  • The documentation has been modified accordingly, like docstring or example tutorials.

@CLAassistant
Copy link

CLAassistant commented Apr 21, 2022

CLA assistant check
All committers have signed the CLA.

@codecov
Copy link

codecov bot commented Apr 21, 2022

Codecov Report

Merging #1496 (f2162bb) into master (618d3c3) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##           master    #1496   +/-   ##
=======================================
  Coverage   90.30%   90.30%           
=======================================
  Files         140      140           
  Lines        8335     8338    +3     
  Branches     1400     1402    +2     
=======================================
+ Hits         7527     7530    +3     
  Misses        570      570           
  Partials      238      238           
Flag Coverage Δ
unittests 90.30% <100.00%> (+<0.01%) ⬆️

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

Impacted Files Coverage Δ
mmseg/models/losses/accuracy.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 618d3c3...f2162bb. Read the comment docs.

@MeowZheng MeowZheng merged commit cb06ff1 into open-mmlab:master Apr 21, 2022
ZhimingNJ pushed a commit to AetrexTechnology/mmsegmentation that referenced this pull request Jun 29, 2022
aravind-h-v pushed a commit to aravind-h-v/mmsegmentation that referenced this pull request Mar 27, 2023
* Add doc for Stable Diffusion on Habana Gaudi

* Make style

* Add benchmark

* Center-align columns in the benchmark table
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