Skip to content
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] assert self.num_levels == len(featmap_sizes) #2200

Closed
3 tasks done
Hevislee opened this issue Jun 20, 2023 · 6 comments · Fixed by #2210
Closed
3 tasks done

[Bug] assert self.num_levels == len(featmap_sizes) #2200

Hevislee opened this issue Jun 20, 2023 · 6 comments · Fixed by #2210
Assignees
Labels
bug Something isn't working mmdet3d onnxruntime

Comments

@Hevislee
Copy link

Checklist

  • I have searched related issues but cannot get the expected help.
  • 2. I have read the FAQ documentation but cannot get the expected help.
  • 3. The bug has not been fixed in the latest version.

Describe the bug

When I was running "python tools/test.py", an error occurred: assert self.num_levels == len(featmap_sizes)
AssertionError.
This error occurs when I run "python tools/test.py" to test pointpillars model, this does not happen when testing centerpoint.

Reproduction

python tools/test.py /home/mmdeploy/configs/mmdet3d/voxel-detection/voxel-detection_onnxruntime_dynamic.py /home/mmdet3d-v1.1/configs/pointpillars/pointpillars_hv_fpn_sbn-all_8xb4-2x_nus-3d.py --model /home/Pointpillars/end2end.onnx --device cuda:0 --speed-test

Environment

06/20 12:47:45 - mmengine - INFO - 06/20 12:47:45 - mmengine - INFO - **********Environmental information**********06/20 12:47:45 - mmengine - INFO - sys.platform: linux06/20 12:47:45 - mmengine - INFO - Python: 3.8.16 | packaged by conda-forge | (default, Feb  1 2023, 16:01:55) [GCC 11.3.0]
06/20 12:47:45 - mmengine - INFO - CUDA available: True
06/20 12:47:45 - mmengine - INFO - numpy_random_seed: 2147483648
06/20 12:47:45 - mmengine - INFO - GPU 0,1,2,3: NVIDIA GeForce RTX 3090
06/20 12:47:45 - mmengine - INFO - CUDA_HOME: /usr/local/cuda-11.1
06/20 12:47:45 - mmengine - INFO - NVCC: Cuda compilation tools, release 11.1, V11.1.105
06/20 12:47:45 - mmengine - INFO - GCC: gcc (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0
06/20 12:47:45 - mmengine - INFO - PyTorch: 1.10.0+cu111
06/20 12:47:45 - mmengine - INFO - PyTorch compiling details: PyTorch built with:
  - GCC 7.3
  - C++ Version: 201402
  - Intel(R) Math Kernel Library Version 2020.0.0 Product Build 20191122 for Intel(R) 64 architecture applications
  - Intel(R) MKL-DNN v2.2.3 (Git Hash 7336ca9f055cf1bfa13efb658fe15dc9b41f0740)
  - OpenMP 201511 (a.k.a. OpenMP 4.5)
  - LAPACK is enabled (usually provided by MKL)
  - NNPACK is enabled
  - CPU capability usage: AVX512
  - CUDA Runtime 11.1
  - NVCC architecture flags: -gencode;arch=compute_37,code=sm_37;-gencode;arch=compute_50,code=sm_50;-gencode;arch=compute_60,code=sm_60;-gencode;arch=compute_70,code=sm_70;-gencode;arch=compute_75,code=sm_75;-gencode;arch=compute_80,code=sm_80;-gencode;arch=compute_86,code=sm_86
  - CuDNN 8.0.5
  - Magma 2.5.2
  - Build settings: BLAS_INFO=mkl, BUILD_TYPE=Release, CUDA_VERSION=11.1, CUDNN_VERSION=8.0.5, CXX_COMPILER=/opt/rh/devtoolset-7/root/usr/bin/c++, CXX_FLAGS= -Wno-deprecated -fvisibility-inlines-hidden -DUSE_PTHREADPOOL -fopenmp -DNDEBUG -DUSE_KINETO -DUSE_FBGEMM -DUSE_QNNPACK -DUSE_PYTORCH_QNNPACK -DUSE_XNNPACK -DSYMBOLICATE_MOBILE_DEBUG_HANDLE -DEDGE_PROFILER_USE_KINETO -O2 -fPIC -Wno-narrowing -Wall -Wextra -Werror=return-type -Wno-missing-field-initializers -Wno-type-limits -Wno-array-bounds -Wno-unknown-pragmas -Wno-sign-compare -Wno-unused-parameter -Wno-unused-variable -Wno-unused-function -Wno-unused-result -Wno-unused-local-typedefs -Wno-strict-overflow -Wno-strict-aliasing -Wno-error=deprecated-declarations -Wno-stringop-overflow -Wno-psabi -Wno-error=pedantic -Wno-error=redundant-decls -Wno-error=old-style-cast -fdiagnostics-color=always -faligned-new -Wno-unused-but-set-variable -Wno-maybe-uninitialized -fno-math-errno -fno-trapping-math -Werror=format -Wno-stringop-overflow, LAPACK_INFO=mkl, PERF_WITH_AVX=1, PERF_WITH_AVX2=1, PERF_WITH_AVX512=1, TORCH_VERSION=1.10.0, USE_CUDA=ON, USE_CUDNN=ON, USE_EXCEPTION_PTR=1, USE_GFLAGS=OFF, USE_GLOG=OFF, USE_MKL=ON, USE_MKLDNN=ON, USE_MPI=OFF, USE_NCCL=ON, USE_NNPACK=ON, USE_OPENMP=ON, 

06/20 12:47:45 - mmengine - INFO - TorchVision: 0.11.0+cu111
06/20 12:47:45 - mmengine - INFO - OpenCV: 4.7.0
06/20 12:47:45 - mmengine - INFO - MMEngine: 0.7.3
06/20 12:47:45 - mmengine - INFO - MMCV: 2.0.0
06/20 12:47:45 - mmengine - INFO - MMCV Compiler: GCC 7.3
06/20 12:47:45 - mmengine - INFO - MMCV CUDA Compiler: 11.1
06/20 12:47:45 - mmengine - INFO - MMDeploy: 1.1.0+439f88b
06/20 12:47:45 - mmengine - INFO - 

06/20 12:47:45 - mmengine - INFO - **********Backend information**********
06/20 12:47:45 - mmengine - INFO - tensorrt:    8.4.2.4
06/20 12:47:45 - mmengine - INFO - tensorrt custom ops: Available
06/20 12:47:45 - mmengine - INFO - ONNXRuntime: None
06/20 12:47:45 - mmengine - INFO - ONNXRuntime-gpu:     1.8.1
06/20 12:47:45 - mmengine - INFO - ONNXRuntime custom ops:      Available
06/20 12:47:45 - mmengine - INFO - pplnn:       None
06/20 12:47:45 - mmengine - INFO - ncnn:        None
06/20 12:47:45 - mmengine - INFO - snpe:        None
06/20 12:47:45 - mmengine - INFO - openvino:    None
06/20 12:47:45 - mmengine - INFO - torchscript: 1.10.0+cu111
06/20 12:47:45 - mmengine - INFO - torchscript custom ops:      NotAvailable
06/20 12:47:45 - mmengine - INFO - rknn-toolkit:        None
06/20 12:47:45 - mmengine - INFO - rknn-toolkit2:       None
06/20 12:47:45 - mmengine - INFO - ascend:      None
06/20 12:47:45 - mmengine - INFO - coreml:      None
06/20 12:47:45 - mmengine - INFO - tvm: None
06/20 12:47:45 - mmengine - INFO - vacc:        None
06/20 12:47:45 - mmengine - INFO - 

06/20 12:47:45 - mmengine - INFO - **********Codebase information**********
06/20 12:47:45 - mmengine - INFO - mmdet:       3.0.0
06/20 12:47:45 - mmengine - INFO - mmseg:       None
06/20 12:47:45 - mmengine - INFO - mmpretrain:  None
06/20 12:47:45 - mmengine - INFO - mmocr:       None
06/20 12:47:45 - mmengine - INFO - mmagic:      None
06/20 12:47:45 - mmengine - INFO - mmdet3d:     1.1.0
06/20 12:47:45 - mmengine - INFO - mmpose:      None
06/20 12:47:45 - mmengine - INFO - mmrotate:    None
06/20 12:47:45 - mmengine - INFO - mmaction:    None
06/20 12:47:45 - mmengine - INFO - mmrazor:     None

Error traceback

/home/mmdetection3d/mmdet3d/models/dense_heads/anchor3d_head.py:92: UserWarning: dir_offset and dir_limit_offset will be depressed and be incorporated into box coder in the future
  warnings.warn(
Traceback (most recent call last):
  File "tools/test.py", line 159, in <module>
    main()
  File "tools/test.py", line 150, in main
    runner.test()
  File "/home/anaconda3/envs/mmdet3d/lib/python3.8/site-packages/mmengine/runner/runner.py", line 1767, in test
    metrics = self.test_loop.run()  # type: ignore
  File "/home/anaconda3/envs/mmdet3d/lib/python3.8/site-packages/mmengine/runner/loops.py", line 435, in run
    self.run_iter(idx, data_batch)
  File "/home/anaconda3/envs/mmdet3d/lib/python3.8/site-packages/torch/autograd/grad_mode.py", line 28, in decorate_context
    return func(*args, **kwargs)
  File "/home/anaconda3/envs/mmdet3d/lib/python3.8/site-packages/mmengine/runner/loops.py", line 454, in run_iter
    outputs = self.runner.model.test_step(data_batch)
  File "/home/anaconda3/envs/mmdet3d/lib/python3.8/site-packages/mmengine/model/base_model/base_model.py", line 145, in test_step
    return self._run_forward(data, mode='predict')  # type: ignore
  File "/home/anaconda3/envs/mmdet3d/lib/python3.8/site-packages/mmengine/model/base_model/base_model.py", line 340, in _run_forward
    results = self(**data, mode=mode)
  File "/home/anaconda3/envs/mmdet3d/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1102, in _call_impl
    return forward_call(*input, **kwargs)
  File "/home/anaconda3/envs/mmdet3d/lib/python3.8/site-packages/mmdeploy/codebase/mmdet3d/deploy/voxel_detection_model.py", line 97, in forward
    prediction = VoxelDetectionModel.postprocess(
  File "/home/anaconda3/envs/mmdet3d/lib/python3.8/site-packages/mmdeploy/codebase/mmdet3d/deploy/voxel_detection_model.py", line 245, in postprocess
    data_instances_3d = head.predict_by_feat(
  File "/home/mmdetection3d/mmdet3d/models/dense_heads/base_3d_dense_head.py", line 232, in predict_by_feat
    mlvl_priors = self.prior_generator.grid_anchors(
  File "/home/mmdetection3d/mmdet3d/models/task_modules/anchor/anchor_3d_generator.py", line 105, in grid_anchors
    assert self.num_levels == len(featmap_sizes)
AssertionError
@RunningLeon
Copy link
Collaborator

hi, are you using the official model config and ckpt from mmdet3d?

@Hevislee
Copy link
Author

hi, are you using the official model config and ckpt from mmdet3d?

yes, i used the official model config and ckpt from mmdet3d.

@RunningLeon
Copy link
Collaborator

RunningLeon commented Jun 20, 2023

@Hevislee hi, there's a bug for fpn models. Here is a simple workaround and pls. change the three files according to the following codes diff or use my temporary branch.

diff --git a/configs/mmdet3d/voxel-detection/voxel-detection_static.py b/configs/mmdet3d/voxel-detection/voxel-detection_static.py
index bba7e819..7f44d78c 100644
--- a/configs/mmdet3d/voxel-detection/voxel-detection_static.py
+++ b/configs/mmdet3d/voxel-detection/voxel-detection_static.py
@@ -3,4 +3,7 @@ codebase_config = dict(
     type='mmdet3d', task='VoxelDetection', model_type='end2end')
 onnx_config = dict(
     input_names=['voxels', 'num_points', 'coors'],
-    output_names=['cls_score', 'bbox_pred', 'dir_cls_pred'])
+    output_names=['cls_score0', 'bbox_pred0', 'dir_cls_pred0',
+                  'cls_score1', 'bbox_pred1', 'dir_cls_pred1',
+                  'cls_score2', 'bbox_pred2', 'dir_cls_pred2',
+                  ])
diff --git a/mmdeploy/codebase/mmdet3d/deploy/voxel_detection_model.py b/mmdeploy/codebase/mmdet3d/deploy/voxel_detection_model.py
index 949f2902..bbbf65f7 100644
--- a/mmdeploy/codebase/mmdet3d/deploy/voxel_detection_model.py
+++ b/mmdeploy/codebase/mmdet3d/deploy/voxel_detection_model.py
@@ -90,7 +90,10 @@ class VoxelDetectionModel(BaseBackendModel):
         }
 
         outputs = self.wrapper(input_dict)
-
+        new_outputs = dict(cls_score=[outputs[f'cls_score{i}'] for i in range(3)],
+                           bbox_pred=[outputs[f'bbox_pred{i}'] for i in range(3)],
+                           dir_cls_pred=[outputs[f'dir_cls_pred{i}'] for i in range(3)])
+        outputs = new_outputs
         if data_samples is None:
             return outputs
 
@@ -239,9 +242,9 @@ class VoxelDetectionModel(BaseBackendModel):
 
         if not hasattr(head, 'task_heads'):
             data_instances_3d = head.predict_by_feat(
-                cls_scores=[cls_score],
-                bbox_preds=[bbox_pred],
-                dir_cls_preds=[dir_cls_pred],
+                cls_scores=cls_score,
+                bbox_preds=bbox_pred,
+                dir_cls_preds=dir_cls_pred,
                 batch_input_metas=batch_input_metas,
                 cfg=cfg)
 
diff --git a/mmdeploy/codebase/mmdet3d/models/mvx_two_stage.py b/mmdeploy/codebase/mmdet3d/models/mvx_two_stage.py
index 12df74ff..632242ed 100644
--- a/mmdeploy/codebase/mmdet3d/models/mvx_two_stage.py
+++ b/mmdeploy/codebase/mmdet3d/models/mvx_two_stage.py
@@ -82,5 +82,8 @@ def mvxtwostagedetector__forward(self, inputs: list, **kwargs):
         dir_scores = torch.cat(dir_scores, dim=1)
         return scores, bbox_preds, dir_scores
     else:
-        cls_score, bbox_pred, dir_cls_pred = outs[0][0], outs[1][0], outs[2][0]
-        return cls_score, bbox_pred, dir_cls_pred
+        # cls_score, bbox_pred, dir_cls_pred = outs[0][0], outs[1][0], outs[2][0]
+        preds = []
+        for i in range(len(outs[0])):
+            preds += [outs[0][i], outs[1][i], outs[2][i]]
+        return tuple(preds)

@RunningLeon RunningLeon added the bug Something isn't working label Jun 20, 2023
@Hevislee
Copy link
Author

Thanks for reply!
I change the three files as above , but another error occurred:
Traceback (most recent call last):
File "tools/test.py", line 159, in
main()
File "tools/test.py", line 150, in main
runner.test()
File "/home/anaconda3/envs/mmdet3d/lib/python3.8/site-packages/mmengine/runner/runner.py", line 1767, in test
metrics = self.test_loop.run() # type: ignore
File "/home/anaconda3/envs/mmdet3d/lib/python3.8/site-packages/mmengine/runner/loops.py", line 435, in run
self.run_iter(idx, data_batch)
File "/home/anaconda3/envs/mmdet3d/lib/python3.8/site-packages/torch/autograd/grad_mode.py", line 28, in decorate_context
return func(*args, **kwargs)
File "/home/anaconda3/envs/mmdet3d/lib/python3.8/site-packages/mmengine/runner/loops.py", line 454, in run_iter
outputs = self.runner.model.test_step(data_batch)
File "/home/anaconda3/envs/mmdet3d/lib/python3.8/site-packages/mmengine/model/base_model/base_model.py", line 145, in test_step
return self._run_forward(data, mode='predict') # type: ignore
File "/home/anaconda3/envs/mmdet3d/lib/python3.8/site-packages/mmengine/model/base_model/base_model.py", line 340, in _run_forward
results = self(**data, mode=mode)
File "/home/anaconda3/envs/mmdet3d/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1102, in _call_impl
return forward_call(*input, **kwargs)
File "/home/mmdeploy/mmdeploy/codebase/mmdet3d/deploy/voxel_detection_model.py", line 92, in forward
outputs = self.wrapper(input_dict)
File "/home/anaconda3/envs/mmdet3d/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1102, in _call_impl
return forward_call(*input, **kwargs)
File "/home/mmdeploy/mmdeploy/backend/onnxruntime/wrapper.py", line 97, in forward
self.__ort_execute(self.io_binding)
File "/home/mmdeploy/mmdeploy/utils/timer.py", line 67, in fun
result = func(*args, **kwargs)
File "/home/mmdeploy/mmdeploy/backend/onnxruntime/wrapper.py", line 113, in __ort_execute
self.sess.run_with_iobinding(io_binding)
File "/home/anaconda3/envs/mmdet3d/lib/python3.8/site-packages/onnxruntime/capi/onnxruntime_inference_collection.py", line 229, in run_with_iobinding
self._sess.run_with_iobinding(iobinding._iobinding, run_options)
RuntimeError: Error in execution: Invalid Output Name:cls_score0

@RunningLeon
Copy link
Collaborator

RunningLeon commented Jun 20, 2023

you should rerun tools/deploy.py to do torch2onnx again.

@Hevislee
Copy link
Author

you should rerun tools/deploy.py to do torch2onnx again.

Suddenly understand!Thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working mmdet3d onnxruntime
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants