-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Dice loss module causes TypeError: forward() got an unexpected keyword argument 'ignore_index'
in v1.1.0
#3172
Comments
i meet the same error🤣 |
I had similar problems when trying to use multiple losses too |
Beside the ignore_index, I think the dice loss implementation has it own logical problem as well. The output_preds has shape [bs, num_classes, H, W] but the target's shape is [bs, H, W], which is cannot be the same shape when flattenning. I think the target has to pass through the one hot encoding first. |
facing similar issue. Any solution to this ,? |
I'm also having a similar issue when using STDC-v2 |
We solved it by just writing a new loss that calculates and combines both losses together, ugly but it works. |
me too..... |
Hi @yeedrag, |
Hi @xiexinch, our solution was to just make a new loss called focal_dice_loss, where we calculate the two losses inside. We didn't modify it in any way. |
Hey @xiexinch, quick question: Im trying to commit my changes, and the pre-commit update-model-index hook modifies all the metafile.yaml files so I couldn't pass the pre-commit check if I only committed the dice_loss.py. Should I also commit the yaml files where the only change is the file paths are modified to be local, or is there a workaround? Sorry I'm not familiar with this and Thanks in advance. |
Added ignore_index param to forward(), also implemented one hot encoding to ensure the dims of target matches pred. 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 Please describe the motivation of this PR and the goal you want to achieve through this PR. Attempted to solve the problems mentioned by #3172 ## Modification Please briefly describe what modification is made in this PR. Added ignore_index into forward function (although the dice loss itself does not actually take account for it for some reason). Added _expand_onehot_labels_dice, which takes the target with shape [N, H, W] into [N, num_classes, H, W]. ## BC-breaking (Optional) Does the modification introduce changes that break the backward-compatibility of the downstream repos? 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 1. Pre-commit or other linting tools are used to fix the potential lint issues. 2. The modification is covered by complete unit tests. If not, please add more unit test to ensure the correctness. 3. If the modification has potential influence on downstream projects, this PR should be tested with downstream projects, like MMDet or MMDet3D. 4. The documentation has been modified accordingly, like docstring or example tutorials. This is my first time contributing to open-source code, so I might have made some stupid mistakes. Please don't hesitate to point it out.
@yeedrag Thank you so much for the fix! I'm closing this issue now as the fix has been merged. |
same question |
…ab#3237) Added ignore_index param to forward(), also implemented one hot encoding to ensure the dims of target matches pred. 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 Please describe the motivation of this PR and the goal you want to achieve through this PR. Attempted to solve the problems mentioned by open-mmlab#3172 ## Modification Please briefly describe what modification is made in this PR. Added ignore_index into forward function (although the dice loss itself does not actually take account for it for some reason). Added _expand_onehot_labels_dice, which takes the target with shape [N, H, W] into [N, num_classes, H, W]. ## BC-breaking (Optional) Does the modification introduce changes that break the backward-compatibility of the downstream repos? 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 1. Pre-commit or other linting tools are used to fix the potential lint issues. 2. The modification is covered by complete unit tests. If not, please add more unit test to ensure the correctness. 3. If the modification has potential influence on downstream projects, this PR should be tested with downstream projects, like MMDet or MMDet3D. 4. The documentation has been modified accordingly, like docstring or example tutorials. This is my first time contributing to open-source code, so I might have made some stupid mistakes. Please don't hesitate to point it out.
…ab#3237) Added ignore_index param to forward(), also implemented one hot encoding to ensure the dims of target matches pred. 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 Please describe the motivation of this PR and the goal you want to achieve through this PR. Attempted to solve the problems mentioned by open-mmlab#3172 ## Modification Please briefly describe what modification is made in this PR. Added ignore_index into forward function (although the dice loss itself does not actually take account for it for some reason). Added _expand_onehot_labels_dice, which takes the target with shape [N, H, W] into [N, num_classes, H, W]. ## BC-breaking (Optional) Does the modification introduce changes that break the backward-compatibility of the downstream repos? 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 1. Pre-commit or other linting tools are used to fix the potential lint issues. 2. The modification is covered by complete unit tests. If not, please add more unit test to ensure the correctness. 3. If the modification has potential influence on downstream projects, this PR should be tested with downstream projects, like MMDet or MMDet3D. 4. The documentation has been modified accordingly, like docstring or example tutorials. This is my first time contributing to open-source code, so I might have made some stupid mistakes. Please don't hesitate to point it out.
…ab#3237) Added ignore_index param to forward(), also implemented one hot encoding to ensure the dims of target matches pred. 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 Please describe the motivation of this PR and the goal you want to achieve through this PR. Attempted to solve the problems mentioned by open-mmlab#3172 ## Modification Please briefly describe what modification is made in this PR. Added ignore_index into forward function (although the dice loss itself does not actually take account for it for some reason). Added _expand_onehot_labels_dice, which takes the target with shape [N, H, W] into [N, num_classes, H, W]. ## BC-breaking (Optional) Does the modification introduce changes that break the backward-compatibility of the downstream repos? 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 1. Pre-commit or other linting tools are used to fix the potential lint issues. 2. The modification is covered by complete unit tests. If not, please add more unit test to ensure the correctness. 3. If the modification has potential influence on downstream projects, this PR should be tested with downstream projects, like MMDet or MMDet3D. 4. The documentation has been modified accordingly, like docstring or example tutorials. This is my first time contributing to open-source code, so I might have made some stupid mistakes. Please don't hesitate to point it out.
Checklist
Describe the bug
Attempted to train SegFormer using Dice loss + CE loss; the following error occurred after updating to mmsegmentation v1.1.0:
Reproduction
Added Dice loss to my config for SegFormer as below:
I believe this issue is directly related to the Dice loss as after removing the Dice loss the error no longer occurs.
Yes, as described above. It used to work with dev-1.* before I updated mmseg to the main branch version.
🤐 Custom datasets, but used to work with dev-1.*
Environment
The text was updated successfully, but these errors were encountered: