open-mmlab / mmdeploy

OpenMMLab Model Deployment Framework
https://mmdeploy.readthedocs.io/en/latest/
Apache License 2.0
2.78k stars 637 forks source link

[Bug] Does not support reg_class_agnostic=True in cascade-rcnn #2838

Open cly234 opened 1 week ago

cly234 commented 1 week ago

Checklist

Describe the bug

When deploying cascade-rcnn, I located that the deployment does not support this config:

bbox_head=[
            dict(
                type='Shared2FCBBoxHead',
                in_channels=256,
                fc_out_channels=1024,
                roi_feat_size=7,
                num_classes=12,
                bbox_coder=dict(
                    type='DeltaXYWHBBoxCoder',
                    target_means=[
                        0.0,
                        0.0,
                        0.0,
                        0.0,
                    ],
                    target_stds=[
                        0.1,
                        0.1,
                        0.2,
                        0.2,
                    ]),
                reg_class_agnostic=False,
                reg_decoded_bbox=True,
                norm_cfg=dict(type='SyncBN', requires_grad=True),
                loss_cls=dict(
                    type='CrossEntropyLoss',
                    use_sigmoid=False,
                    loss_weight=1.0),
                loss_bbox=dict(type='CIoULoss', loss_weight=12.0))

where the reg_class_agnostic is set to False. The reason is that the code in the deployment was like:

if i < self.num_stages - 1:
            assert self.bbox_head[i].reg_class_agnostic
            new_rois = self.bbox_head[i].bbox_coder.decode(
                rois[..., 1:], bbox_pred, max_shape=max_shape)
            new_rois = get_box_tensor(new_rois)
            rois = new_rois.reshape(-1, new_rois.shape[-1])
            # Add dummy batch index
            rois = torch.cat([batch_index.flatten(0, 1), rois], dim=-1)

Error traceback

results_list = self.predict_bbox(
  File "/usr/local/python/lib/python3.8/site-packages/mmdeploy/codebase/mmdet/models/roi_heads/cascade_roi_head.py", line 66, in cascade_roi_head__predict_bbox
    assert self.bbox_head[i].reg_class_agnostic
AssertionError
cly234 commented 6 days ago

Update: Fix this by selecting the highest score among classes for each roi and enabling batch-level inference.