Repository: open-mmlab/mmdeploy

Issue:
[BUG] mmdeploy test coco val  bbox bug
Thanks for your bug report. We appreciate it a lot.

**Checklist**

1. I have searched related issues but cannot get the expected help.
2. I have read the [FAQ documentation](https://github.com/open-mmlab/mmdeploy/blob/master/docs/en/faq.md) but cannot get the expected help.
3. The bug has not been fixed in the latest version.

**Describe the bug**

使用测试脚本检测coco bbox时显示TypeError: show_result() got an unexpected keyword argument 'bbox_color'

**Reproduction**

(mm) ubuntu@y9000p:~/work/COCO/mmdeploy$ python tools/deploy.py     configs/mmdet/detection/detection_tensorrt_dynamic-416x416-864x864.py     ../mmdetection/configs/yolox/yolox_s_8x8_300e_coco.py ../checkpoints/yolox_s_8x8_300e_coco_20211121_095711-4592a793.pth   demo/demo.jpg    --work-dir work_dir_yolox-s_fp32  --device cuda:0 --dump-info
2022-02-23 17:12:34,522 - mmdeploy - INFO - torch2onnx start.
load checkpoint from local path: ../checkpoints/yolox_s_8x8_300e_coco_20211121_095711-4592a793.pth
/home/ubuntu/miniconda3/envs/mm/lib/python3.8/site-packages/torch/onnx/utils.py:97: UserWarning: `strip_doc_string' is deprecated and ignored. Will be removed in next PyTorch release. It's combined with `verbose' argument now. 
  warnings.warn("`strip_doc_string' is deprecated and ignored. Will be removed in "
/home/ubuntu/work/COCO/mmdeploy/mmdeploy/core/optimizers/function_marker.py:158: TracerWarning: Converting a tensor to a Python integer might cause the trace to be incorrect. We can't record the data flow of Python values, so this value will be treated as a constant in the future. This means that the trace might not generalize to other inputs!
  ys_shape = tuple(int(s) for s in ys.shape)
/home/ubuntu/miniconda3/envs/mm/lib/python3.8/site-packages/torch/functional.py:445: UserWarning: torch.meshgrid: in an upcoming release, it will be required to pass the indexing argument. (Triggered internally at  ../aten/src/ATen/native/TensorShape.cpp:2157.)
  return _VF.meshgrid(tensors, **kwargs)  # type: ignore[attr-defined]
/home/ubuntu/work/COCO/mmdeploy/mmdeploy/codebase/mmdet/core/post_processing/bbox_nms.py:260: TracerWarning: Converting a tensor to a Python integer might cause the trace to be incorrect. We can't record the data flow of Python values, so this value will be treated as a constant in the future. This means that the trace might not generalize to other inputs!
  dets, labels = TRTBatchedNMSop.apply(boxes, scores, int(scores.shape[-1]),
/home/ubuntu/work/COCO/mmdeploy/mmdeploy/mmcv/ops/nms.py:177: TracerWarning: Converting a tensor to a Python boolean might cause the trace to be incorrect. We can't record the data flow of Python values, so this value will be treated as a constant in the future. This means that the trace might not generalize to other inputs!
  out_boxes = min(num_boxes, after_topk)
WARNING: The shape inference of mmdeploy::TRTBatchedNMS type is missing, so it may result in wrong shape inference for the exported graph. Please consider adding it in symbolic function.
WARNING: The shape inference of mmdeploy::TRTBatchedNMS type is missing, so it may result in wrong shape inference for the exported graph. Please consider adding it in symbolic function.
WARNING: The shape inference of mmdeploy::TRTBatchedNMS type is missing, so it may result in wrong shape inference for the exported graph. Please consider adding it in symbolic function.
WARNING: The shape inference of mmdeploy::TRTBatchedNMS type is missing, so it may result in wrong shape inference for the exported graph. Please consider adding it in symbolic function.
WARNING: The shape inference of mmdeploy::TRTBatchedNMS type is missing, so it may result in wrong shape inference for the exported graph. Please consider adding it in symbolic function.
WARNING: The shape inference of mmdeploy::TRTBatchedNMS type is missing, so it may result in wrong shape inference for the exported graph. Please consider adding it in symbolic function.
2022-02-23 17:12:44,897 - mmdeploy - INFO - torch2onnx success.
2022-02-23 17:12:45,012 - mmdeploy - INFO - onnx2tensorrt of work_dir_yolox-s_fp32/end2end.onnx start.
2022-02-23 17:12:45,993 - mmdeploy - INFO - Successfully loaded tensorrt plugins from /home/ubuntu/work/COCO/mmdeploy/build/lib/libmmdeploy_tensorrt_ops.so
[02/23/2022-17:12:46] [TRT] [I] [MemUsageChange] Init CUDA: CPU +357, GPU +0, now: CPU 436, GPU 1910 (MiB)
[02/23/2022-17:12:46] [TRT] [I] [MemUsageSnapshot] Begin constructing builder kernel library: CPU 456 MiB, GPU 1910 MiB
[02/23/2022-17:12:47] [TRT] [I] [MemUsageSnapshot] End constructing builder kernel library: CPU 831 MiB, GPU 2032 MiB
[02/23/2022-17:12:47] [TRT] [W] onnx2trt_utils.cpp:365: Your ONNX model has been generated with INT64 weights, while TensorRT does not natively support INT64. Attempting to cast down to INT32.
[02/23/2022-17:12:47] [TRT] [W] onnx2trt_utils.cpp:391: One or more weights outside the range of INT32 was clamped
[02/23/2022-17:12:47] [TRT] [W] onnx2trt_utils.cpp:391: One or more weights outside the range of INT32 was clamped
[02/23/2022-17:12:47] [TRT] [W] onnx2trt_utils.cpp:391: One or more weights outside the range of INT32 was clamped
[02/23/2022-17:12:47] [TRT] [W] onnx2trt_utils.cpp:391: One or more weights outside the range of INT32 was clamped
[02/23/2022-17:12:47] [TRT] [W] onnx2trt_utils.cpp:391: One or more weights outside the range of INT32 was clamped
[02/23/2022-17:12:47] [TRT] [W] onnx2trt_utils.cpp:391: One or more weights outside the range of INT32 was clamped
[02/23/2022-17:12:47] [TRT] [W] onnx2trt_utils.cpp:391: One or more weights outside the range of INT32 was clamped
[02/23/2022-17:12:47] [TRT] [W] onnx2trt_utils.cpp:391: One or more weights outside the range of INT32 was clamped
[02/23/2022-17:12:47] [TRT] [W] onnx2trt_utils.cpp:391: One or more weights outside the range of INT32 was clamped
[02/23/2022-17:12:47] [TRT] [W] onnx2trt_utils.cpp:391: One or more weights outside the range of INT32 was clamped
[02/23/2022-17:12:47] [TRT] [W] onnx2trt_utils.cpp:391: One or more weights outside the range of INT32 was clamped
[02/23/2022-17:12:47] [TRT] [I] No importer registered for op: TRTBatchedNMS. Attempting to import as plugin.
[02/23/2022-17:12:47] [TRT] [I] Searching for plugin: TRTBatchedNMS, plugin_version: 1, plugin_namespace: 
[02/23/2022-17:12:47] [TRT] [I] Successfully created plugin: TRTBatchedNMS
[02/23/2022-17:12:50] [TRT] [W] TensorRT was linked against cuBLAS/cuBLAS LT 11.8.0 but loaded cuBLAS/cuBLAS LT 11.6.5
[02/23/2022-17:12:50] [TRT] [I] [MemUsageChange] Init cuBLAS/cuBLASLt: CPU +773, GPU +342, now: CPU 5713, GPU 4252 (MiB)
[02/23/2022-17:12:51] [TRT] [I] [MemUsageChange] Init cuDNN: CPU +189, GPU +344, now: CPU 5902, GPU 4596 (MiB)
[02/23/2022-17:12:51] [TRT] [W] TensorRT was linked against cuDNN 8.3.2 but loaded cuDNN 8.2.4
[02/23/2022-17:12:51] [TRT] [I] Local timing cache in use. Profiling results in this builder pass will not be stored.
[02/23/2022-17:13:04] [TRT] [I] Some tactics do not have sufficient workspace memory to run. Increasing workspace size will enable more tactics, please check verbose output for requested sizes.
[02/23/2022-17:13:40] [TRT] [I] Detected 1 inputs and 2 output network tensors.
[02/23/2022-17:13:40] [TRT] [W] Max value of this profile is not valid
[02/23/2022-17:13:40] [TRT] [W] Min value of this profile is not valid
[02/23/2022-17:13:40] [TRT] [I] Total Host Persistent Memory: 170160
[02/23/2022-17:13:40] [TRT] [I] Total Device Persistent Memory: 2591232
[02/23/2022-17:13:40] [TRT] [I] Total Scratch Memory: 19463168
[02/23/2022-17:13:40] [TRT] [I] [MemUsageStats] Peak memory usage of TRT CPU/GPU memory allocators: CPU 11 MiB, GPU 572 MiB
[02/23/2022-17:13:40] [TRT] [I] [BlockAssignment] Algorithm ShiftNTopDown took 90.5823ms to assign 23 blocks to 212 nodes requiring 65445400 bytes.
[02/23/2022-17:13:40] [TRT] [I] Total Activation Memory: 65445400
[02/23/2022-17:13:40] [TRT] [W] TensorRT was linked against cuBLAS/cuBLAS LT 11.8.0 but loaded cuBLAS/cuBLAS LT 11.6.5
[02/23/2022-17:13:40] [TRT] [I] [MemUsageChange] Init cuBLAS/cuBLASLt: CPU +0, GPU +8, now: CPU 6830, GPU 5120 (MiB)
[02/23/2022-17:13:40] [TRT] [I] [MemUsageChange] Init cuDNN: CPU +0, GPU +8, now: CPU 6830, GPU 5128 (MiB)
[02/23/2022-17:13:40] [TRT] [W] TensorRT was linked against cuDNN 8.3.2 but loaded cuDNN 8.2.4
[02/23/2022-17:13:40] [TRT] [I] [MemUsageChange] TensorRT-managed allocation in building engine: CPU +6, GPU +43, now: CPU 6, GPU 43 (MiB)
2022-02-23 17:13:41,633 - mmdeploy - INFO - onnx2tensorrt of work_dir_yolox-s_fp32/end2end.onnx success.
2022-02-23 17:13:41,633 - mmdeploy - INFO - visualize tensorrt model start.
2022-02-23 17:13:46,027 - mmdeploy - INFO - Successfully loaded tensorrt plugins from /home/ubuntu/work/COCO/mmdeploy/build/lib/libmmdeploy_tensorrt_ops.so
2022-02-23 17:13:46,027 - mmdeploy - INFO - Successfully loaded tensorrt plugins from /home/ubuntu/work/COCO/mmdeploy/build/lib/libmmdeploy_tensorrt_ops.so
[02/23/2022-17:13:46] [TRT] [W] TensorRT was linked against cuBLAS/cuBLAS LT 11.8.0 but loaded cuBLAS/cuBLAS LT 11.6.5
[02/23/2022-17:13:47] [TRT] [W] TensorRT was linked against cuDNN 8.3.2 but loaded cuDNN 8.2.4
[02/23/2022-17:13:47] [TRT] [W] TensorRT was linked against cuBLAS/cuBLAS LT 11.8.0 but loaded cuBLAS/cuBLAS LT 11.6.5
[02/23/2022-17:13:47] [TRT] [W] TensorRT was linked against cuDNN 8.3.2 but loaded cuDNN 8.2.4
2022-02-23 17:13:51,509 - mmdeploy - INFO - visualize tensorrt model success.
2022-02-23 17:13:51,509 - mmdeploy - INFO - visualize pytorch model start.
load checkpoint from local path: ../checkpoints/yolox_s_8x8_300e_coco_20211121_095711-4592a793.pth
/home/ubuntu/miniconda3/envs/mm/lib/python3.8/site-packages/torch/functional.py:445: UserWarning: torch.meshgrid: in an upcoming release, it will be required to pass the indexing argument. (Triggered internally at  ../aten/src/ATen/native/TensorShape.cpp:2157.)
  return _VF.meshgrid(tensors, **kwargs)  # type: ignore[attr-defined]
/home/ubuntu/work/COCO/mmdetection/mmdet/models/dense_heads/yolox_head.py:284: UserWarning: Creating a tensor from a list of numpy.ndarrays is extremely slow. Please consider converting the list to a single numpy.ndarray with numpy.array() before converting to a tensor. (Triggered internally at  ../torch/csrc/utils/tensor_new.cpp:201.)
  flatten_bboxes[..., :4] /= flatten_bboxes.new_tensor(
2022-02-23 17:13:59,175 - mmdeploy - INFO - visualize pytorch model success.
2022-02-23 17:13:59,175 - mmdeploy - INFO - All process success.
(mm) ubuntu@y9000p:~/work/COCO/mmdeploy$ python tools/test.py     configs/mmdet/detection/detection_tensorrt_dynamic-416x416-864x864.py     ../mmdetection/configs/yolox/yolox_s_8x8_300e_coco.py     --model work_dir_yolox-s_fp32/end2end.engine     --metrics bbox     --device cuda:0 --show
loading annotations into memory...
Done (t=0.34s)
creating index...
index created!
2022-02-23 17:14:33,044 - mmdeploy - INFO - Successfully loaded tensorrt plugins from /home/ubuntu/work/COCO/mmdeploy/build/lib/libmmdeploy_tensorrt_ops.so
2022-02-23 17:14:33,044 - mmdeploy - INFO - Successfully loaded tensorrt plugins from /home/ubuntu/work/COCO/mmdeploy/build/lib/libmmdeploy_tensorrt_ops.so
[02/23/2022-17:14:33] [TRT] [W] TensorRT was linked against cuBLAS/cuBLAS LT 11.8.0 but loaded cuBLAS/cuBLAS LT 11.6.5
[02/23/2022-17:14:34] [TRT] [W] TensorRT was linked against cuDNN 8.3.2 but loaded cuDNN 8.2.4
[02/23/2022-17:14:34] [TRT] [W] TensorRT was linked against cuBLAS/cuBLAS LT 11.8.0 but loaded cuBLAS/cuBLAS LT 11.6.5
[02/23/2022-17:14:34] [TRT] [W] TensorRT was linked against cuDNN 8.3.2 but loaded cuDNN 8.2.4
[                                                  ] 0/5000, elapsed: 0s, ETA:Traceback (most recent call last):
  File "tools/test.py", line 137, in <module>
    main()
  File "tools/test.py", line 129, in main
    outputs = task_processor.single_gpu_test(model, data_loader, args.show,
  File "/home/ubuntu/work/COCO/mmdeploy/mmdeploy/codebase/base/task.py", line 137, in single_gpu_test
    return self.codebase_class.single_gpu_test(model, data_loader, show,
  File "/home/ubuntu/work/COCO/mmdeploy/mmdeploy/codebase/mmdet/deploy/mmdetection.py", line 142, in single_gpu_test
    outputs = single_gpu_test(model, data_loader, show, out_dir, **kwargs)
  File "/home/ubuntu/work/COCO/mmdetection/mmdet/apis/test.py", line 53, in single_gpu_test
    model.module.show_result(
TypeError: show_result() got an unexpected keyword argument 'bbox_color'

**Environment**

mmcv mmdeploy mmdetection均最新

**Error traceback**

If applicable, paste the error trackback here.

```none
A placeholder for trackback.
```

**Bug fix**

If you have already identified the reason, you can provide the information here. If you are willing to create a PR to fix it, please also leave a comment here and that would be much appreciated!



Discussion:
Hi @q3394101, could you please provide the testing scripts you used?
CLose since no activity for quite a long time
i have same problem,anyone konws how to fix this ?
Any idea what's happening here? 

TypeError: show_result() got an unexpected keyword argument 'bbox_color' - I get the same error and below are the things i'm using:

test.py from mmdet/apis and test.py from mmdeploy/tools/test.py. 
below is the testing CLI I used:

**Deployment:**
python tools/deploy.py \
    configs/mmdet/detection/detection_tensorrt-fp16_dynamic-320x320-1344x1344.py \
    ../mmdetection/mmdetection/configs/faster_rcnn/faster_rcnn_r50_fpn_2x_coco.py \
    ../mmdetection/checkpoints/faster_rcnn_r50_fpn_2x_coco_bbox_mAP-0.384_20200504_210434-a5d8aa15.pth \
    ../mmdetection/demo/demo.jpg \
    --work-dir work_dir \
    --device cuda:0 \
    --log-level INFO \
    --show \
    --dump-info
    

**Testing:**
python tools/test.py \
    configs/mmdet/detection/detection_tensorrt-fp16_dynamic-320x320-1344x1344.py \
    ../mmdetection/mmdetection/configs/faster_rcnn/faster_rcnn_r50_fpn_2x_coco.py \
    --model work_dir/end2end.engine \
    --out out.pkl \
    --device cuda:0 \
    --show-dir work_dir \
    --metrics bbox
i have same problem,anyone konws how to fix this ?

Deployment:
DEPLOY_CFG_PATH="configs/mmdet/instance-seg/instance-seg_onnxruntime_dynamic.py"
MODEL_CFG_PATH="../mmdetection/configs/ips_zh/exp3_8_mask_rcnn_r50_fpn_1x_coco_pretrained_ips21_frozen2.py"
MODEL_CHECKPOINT_PATH="../mmdetection/exps/exp3_8_mask_rcnn_r50_fpn_1x_coco_pretrained_ips21_frozen2/latest.pth"
INPUT_IMG='../mmdetection/ips_images/v2.1&v2.0/192.168.1.7_ch1_20220520151530_20220520154222_01374.jpg'
TEST_IMG='../mmdetection/ips_images/v2.1&v2.0/192.168.1.7_ch1_20220520151530_20220520154222_01374.jpg'
WORK_DIR="outputs"
python ./tools/deploy.py \
    ${DEPLOY_CFG_PATH} \
    ${MODEL_CFG_PATH} \
    ${MODEL_CHECKPOINT_PATH} \
    ${INPUT_IMG} \
    --test-img ${TEST_IMG} \
    --work-dir ${WORK_DIR} \
    --device cuda:0 \
    --log-level INFO \
    --show

Testing:
DEPLOY_CFG="configs/mmdet/instance-seg/instance-seg_onnxruntime_dynamic.py"
MODEL_CFG="../mmdetection/configs/ips_zh/exp3_8_mask_rcnn_r50_fpn_1x_coco_pretrained_ips21_frozen2.py"
BACKEND_MODEL_FILES="outputs/end2end.onnx"
OUTPUT_PKL_FILE="output/result.pkl"
OUTPUT_IMAGE_DIR="output/temp"
python tools/test.py \
    ${DEPLOY_CFG} \
    ${MODEL_CFG} \
    --model ${BACKEND_MODEL_FILES} \
    --out ${OUTPUT_PKL_FILE} \
    --metrics "bbox" "segm" \
    --show \
    --show-dir ${OUTPUT_IMAGE_DIR\
    --device cuda:0

![Screenshot from 2022-07-14 17-28-30](https://user-images.githubusercontent.com/107545756/178951264-b1aca1ee-9a0f-4606-a84b-8ac22de29221.png)



I have same problem @AllentDan 

mmdeploy               0.7.0
mmdet                  2.24.0
mmcv-full              1.5.3

 I used the following command
```python
python tools/test.py configs/mmdet/detection/detection_tensorrt-fp16_dynamic-320x320-1344x1344.py ../mmlab/mmdetection/configs/yolox/yolox_s_8x8_300e_coco.py --model ../mmlab/mmdeploy/out/yolox_s/end2end.engine --show-dir out/ --device cuda:0 --batch-size 1 --speed-test  --warmup 1
```
```
 File "tools/test.py", line 148, in <module>
    main()
  File "tools/test.py", line 137, in main
    outputs = task_processor.single_gpu_test(model, data_loader,
  File "/root/workspace/mmdeploy/mmdeploy/codebase/base/task.py", line 139, in single_gpu_test
    return self.codebase_class.single_gpu_test(model, data_loader, show,
  File "/root/workspace/mmdeploy/mmdeploy/codebase/mmdet/deploy/mmdetection.py", line 142, in single_gpu_test
    outputs = single_gpu_test(model, data_loader, show, out_dir, **kwargs)
  File "/opt/conda/lib/python3.8/site-packages/mmdet/apis/test.py", line 53, in single_gpu_test
    model.module.show_result(
TypeError: show_result() got an unexpected keyword argument 'bbox_color'
```
I located the source of the problem

mmlab/mmdeploy/mmdeploy/codebase/mmdet/deploy/object_detection_model.py :
```python
class End2EndModel(BaseBackendModel):
    def show_result(self,
                    img: np.ndarray,
                    result: list,
                    win_name: str = '',
                    show: bool = True,
                    score_thr: float = 0.3,
                    out_file=None):
        return BaseDetector.show_result(
            self,
            img=img,
            result=result,
            score_thr=score_thr,
            show=show,
            win_name=win_name,
            out_file=out_file)
```
but mmdet mmlab/mmdetection/mmdet/models/detectors/base.py    BaseDetector.show_result 

Maybe mmdet provides bbox_color by default when calling show_result
``` python
class BaseDetector(BaseModule, metaclass=ABCMeta):
    def show_result(self,
                    img,
                    result,
                    score_thr=0.3,
                    bbox_color=(72, 101, 241),
                    text_color=(72, 101, 241),
                    mask_color=None,
                    thickness=2,
                    font_size=13,
                    win_name='',
                    show=False,
                    wait_time=0,
                    out_file=None):
...
```
I modified object_detection_model.py 
``` python
    def show_result(self,
                    img: np.ndarray,
                    result: list,
                    win_name: str = '',
                    show: bool = True,
                    score_thr: float = 0.3,
                    bbox_color = None,
                    text_color = None,
                    mask_color = None,
                    out_file=None):
        return BaseDetector.show_result(
            self,
            img=img,
            result=result,
            score_thr=score_thr,
            show=show,
            win_name=win_name,
            out_file=out_file)
```

Everything seems to be working fine, I get the picture of the output, can you check if this is a bug
Hi, @munhou . Thanks for reporting the bug. Would you mind pulling a request to MMDeploy to fix it?
> 

@AllentDan  I'm actively making my first contribution to an open source project and I think this is a great opportunity to try

Resolving patch:
diff --git a/mmdeploy/codebase/mmdet/deploy/object_detection_model.py b/mmdeploy/codebase/mmdet/deploy/object_detection_model.py
--- a/mmdeploy/codebase/mmdet/deploy/object_detection_model.py
+++ b/mmdeploy/codebase/mmdet/deploy/object_detection_model.py
@@ -281,7 +281,8 @@ def show_result(self,
                     win_name: str = '',
                     show: bool = True,
                     score_thr: float = 0.3,
-                    out_file=None):
+                    out_file=None,
+                    **kwargs):
         return BaseDetector.show_result(
             self,
             img=img,
@@ -289,7 +290,8 @@ def show_result(self,
             score_thr=score_thr,
             show=show,
             win_name=win_name,
-            out_file=out_file)
+            out_file=out_file,
+            **kwargs)
 
 
 @__BACKEND_MODEL.register_module('single_stage')


Test patch: