-
Notifications
You must be signed in to change notification settings - Fork 644
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
[Bug] Error Exporting RetinaNet for Single Class Case with CrossEntropyLoss in MMDeploy #2787
Comments
Hi, good day to you maintainers! May I know will there be any action plans for this 👀? |
Thanks for the notification. This should be a bug of a big refactor #1091. Removing either of the slices should be ok. |
@grimoire ,thank you for your response. Could you let me know if a patch release is planned, and if so, when we might expect it? |
Sure, that would be cool. |
Checklist
Describe the bug
I am facing an issue when exporting the RetinaNet from mmdetection (https://github.com/open-mmlab/mmdetection/blob/main/configs/_base_/models/retinanet_r50_fpn.py) for a single class case. IndexError was raised due to the sliced
nms_pre_score
having zero-dimI modified the classification loss function to employ Cross Entropy (
type='CrossEntropyLoss', use_sigmoid=True, loss_weight=1.0
), in such the effective bbox_head config would be as follow:To export the model into ONNX, I called the
export
function from https://github.com/open-mmlab/mmdeploy/blob/bc75c9d6c8940aa03d0e1e5b5962bd930478ba77/mmdeploy/apis/onnx/export.py. Based on my understanding, beforetorch.onnx.export
was invoked, the model is patched with modified child modules and for this particular case, thepredict_with_feat()
is replaced withbase_dense_head__predict_by_feat()
inmmdeploy/mmdeploy/codebase/mmdet/models/dense_heads/base_dense_head.py
Lines 26 to 27 in bc75c9d
After reviewing the code in
mmdeploy/mmdeploy/codebase/mmdet/models/dense_heads/base_dense_head.py
Lines 26 to 27 in bc75c9d
I noticed three parts involving the
use_sigmoid
flag configured in the CrossEntropyLoss, namely:At the constructor of the RetinaHead : https://github.com/open-mmlab/mmdetection/blob/cfd5d3a985b0249de009b67d04f37263e11cdf3d/mmdet/models/dense_heads/anchor_head.py#L73-L78
At the base_dense_head, there is first slicing of the
scores
. I presume this is to exclude the background (indexnum_classes
):mmdeploy/mmdeploy/codebase/mmdet/models/dense_heads/base_dense_head.py
Lines 113 to 117 in bc75c9d
This is the confusing part, there is a second round of slicing when getting the max_scores:
mmdeploy/mmdeploy/codebase/mmdet/models/dense_heads/base_dense_head.py
Lines 141 to 146 in bc75c9d
I hope you could explain the reasoning behind this, as it appears that the last object class is excluded when computing the
max_scores
. Thank you!Reproduction
Environment
Error traceback
/cc @RunningLeon @grimoire
The text was updated successfully, but these errors were encountered: