-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Precarious label map creation when using custom classes #2493
Comments
Thanks for your bug report, and for other high-quality PR from you. 👍 We also found it is not robust, and modify it in MMSegmentation 1.x mmsegmentation/mmseg/datasets/basesegdataset.py Lines 181 to 185 in a115b10
In new mmseg, we give up the unstable underflows, just set the default ignore value 255 in decode head of mmseg model. Do you have any comments about this modification? Are there any potential bugs we haven't thought of? |
Thanks for your prompt replies!
Thanks for pointing out that this has been fixed in 1.x. I think for now, this is an okay fix, but it can be improved. Currently, at various places in both the master and 1.x branches,
I think this is not urgent; the current fix you have works for now. I had no idea that a 1.x branch existed! Thanks for pointing it out. I have a few questions:
In the meantime, I'll create a PR for |
I created two PRs:
|
I prefer this solution, and for avoiding bc-breaking,
yes
1.x now is pre-released and we will officially release it in Q1 2023
no. 1.x branch will be renamed as master and original master will be renamed as 0.x when mmseg 1.x is released. Here is migration documentation, if you have any questions or suggestions, just let us know, |
## Motivation This fixes #2493. When the `label_map` is created, the index for ignored classes was being set to -1, whereas the index that is actually ignored is 255. This worked indirectly since -1 was underflowed to 255 when converting to uint8. The same fix was made in the 1.x by #2332 but this fix was never made to `master`. ## Modification The only small modification is setting the index of ignored classes to 255 instead of -1. ## Checklist - [x] Pre-commit or other linting tools are used to fix the potential lint issues. - _I've fixed all linting/pre-commit errors._ - [x] The modification is covered by complete unit tests. If not, please add more unit test to ensure the correctness. - _No unit tests need to be added. Unit tests that are affected were modified. - [x] If the modification has potential influence on downstream projects, this PR should be tested with downstream projects, like MMDet or MMDet3D. - _I don't think this change affects MMDet or MMDet3D._ - [x] The documentation has been modified accordingly, like docstring or example tutorials. - _This change fixes an existing bug and doesn't require modifying any documentation/docstring._
Fixed by #2515 that is now merged. |
When using custom classes, the label map is created in this way (copied below). This code fragment is fragile because missing classes are mapped to "-1", but the "-1" is never handled properly.
I've tried to understand how this "-1" label is handled when training. The expected behavior is that this "-1" label should be ignored. However, this behavior is achieved very indirectly and precariously (prone to bugs):
In loading.py:
gt_semantic_seg
is created with typeuint8
. Then,When
new_id
is -1, uint8 underflows to 255. Then, since the defaultignore_index=255
in custom.py, the "-1" label is successfully ignored.My issue is that this process is not explicit and can be prone to bugs. For example, the uint8 masks are eventually converted to
torch.Tensor
of typeint64
, which can contain negative values. The code only works just because an intermediate step happened to use uint8 and the underflow occurred.I think the code should be improved and the "-1" label should be handled more explicitly, by, for example, always ignoring negative labels in addition to ignoring the (optional)
ignore_index
label.The text was updated successfully, but these errors were encountered: