open-mmlab / mmdeploy

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

[Bug] grounding_dino Deploy torch2onnx 出错 #2697

Open hymnli opened 4 months ago

hymnli commented 4 months ago

Checklist

Describe the bug

使用 deploy tools/torch2onnx.py 将grounding_dino 模型 groundingdino_swint_ogc_mmdet-822d7e9d.pth 转换为 onnx时报错

${DEPLOY_CFG_PATH}/mmdet/detection/detection_onnxruntime_static.py \
${MODEL_CFG_PATH}/grounding_dino/grounding_dino_swin-t_pretrain_obj365_goldg_cap4m.py \
${MODEL_CHECKPOINT_PATH}/groundingdino_swint_ogc_mmdet-822d7e9d.pth \
${INPUT_DIR}/images/firc_accident_5.jpg \
--work-dir ${WORK_DIR}/mmdeploy_models/mmdet/grounding_dino \
--device cpu \
--log-level INFO

03/12 11:26:12 - mmengine - INFO - torch2onnx: model_cfg: /home/srd-user/workspace/mmlab_prj/mmdetection/configs/grounding_dino/grounding_dino_swin-t_pretrain_obj365_goldg_cap4m.py deploy_cfg: /home/srd-user/workspace/mmlab_prj/mmdeploy/configs/mmdet/detection/detection_onnxruntime_static.py 03/12 11:26:17 - mmengine - WARNING - Failed to search registry with scope "mmdet" in the "Codebases" registry tree. As a workaround, the current "Codebases" registry in "mmdeploy" is used to build instance. This may cause unexpected failure when running the built modules. Please check whether "mmdet" is a correct scope, or whether the registry is initialized. 03/12 11:26:17 - mmengine - WARNING - Failed to search registry with scope "mmdet" in the "mmdet_tasks" registry tree. As a workaround, the current "mmdet_tasks" registry in "mmdeploy" is used to build instance. This may cause unexpected failure when running the built modules. Please check whether "mmdet" is a correct scope, or whether the registry is initialized. Loads checkpoint by local backend from path: /home/srd-user/workspace/mmlab_prj/mmdetection/checkpoint/groundingdino_swint_ogc_mmdet-822d7e9d.pth The model and loaded state dict do not match exactly

unexpected key in source state_dict: language_model.language_backbone.body.model.embeddings.position_ids

missing keys in source state_dict: dn_query_generator.label_embedding.weight

03/12 11:26:41 - mmengine - WARNING - DeprecationWarning: get_onnx_config will be deprecated in the future. 03/12 11:26:41 - mmengine - INFO - Export PyTorch model to ONNX: /home/srd-user/workspace/mmlab_prj/mmdetection/work_dirs/mmdeploy_models/mmdet/grounding_dino/end2end.onnx. /home/srd-user/workspace/mmlab_prj/mmdeploy/mmdeploy/codebase/mmdet/models/detectors/base_detr.py:85: TracerWarning: Iterating over a tensor might cause the trace to be incorrect. Passing a tensor of different shape won't change the number of iterations executed (and might lead to errors or silently give incorrect results). img_shape = [int(val) for val in img_shape] /home/srd-user/workspace/mmlab_prj/mmdeploy/mmdeploy/codebase/mmdet/models/detectors/base_detr.py:85: 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! img_shape = [int(val) for val in img_shape] /home/srd-user/workspace/mmlab_prj/mmdeploy/mmdeploy/core/optimizers/function_marker.py:160: 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/srd-user/.conda/envs/mmlab_dep_cu118/lib/python3.8/site-packages/mmdet/models/layers/transformer/utils.py:167: TracerWarning: Converting a tensor to a Python float 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! output_h = math.ceil(input_h / stride_h) /home/srd-user/.conda/envs/mmlab_dep_cu118/lib/python3.8/site-packages/mmdet/models/layers/transformer/utils.py:168: TracerWarning: Converting a tensor to a Python float 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! output_w = math.ceil(input_w / stride_w) /home/srd-user/.conda/envs/mmlab_dep_cu118/lib/python3.8/site-packages/mmdet/models/layers/transformer/utils.py:169: 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! pad_h = max((output_h - 1) stride_h + /home/srd-user/.conda/envs/mmlab_dep_cu118/lib/python3.8/site-packages/mmdet/models/layers/transformer/utils.py:171: 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! pad_w = max((output_w - 1) stride_w + /home/srd-user/.conda/envs/mmlab_dep_cu118/lib/python3.8/site-packages/mmdet/models/layers/transformer/utils.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! if pad_h > 0 or pad_w > 0: /home/srd-user/workspace/mmlab_prj/mmdeploy/mmdeploy/codebase/mmdet/models/backbones.py:189: 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! assert L == H W, 'input feature has wrong size' /home/srd-user/.conda/envs/mmlab_dep_cu118/lib/python3.8/site-packages/mmdet/models/backbones/swin.py:267: 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! B = int(windows.shape[0] / (H W / window_size / window_size)) /home/srd-user/.conda/envs/mmlab_dep_cu118/lib/python3.8/site-packages/mmdet/models/layers/transformer/utils.py:414: 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! assert L == H W, 'input feature has wrong size' Traceback (most recent call last): File "tools/torch2onnx.py", line 85, in main() File "tools/torch2onnx.py", line 47, in main torch2onnx( File "/home/srd-user/workspace/mmlab_prj/mmdeploy/mmdeploy/apis/core/pipeline_manager.py", line 356, in _wrap return self.call_function(funcname, args, kwargs) File "/home/srd-user/workspace/mmlab_prj/mmdeploy/mmdeploy/apis/core/pipeline_manager.py", line 326, in call_function return self.call_function_local(func_name, *args, *kwargs) File "/home/srd-user/workspace/mmlab_prj/mmdeploy/mmdeploy/apis/core/pipeline_manager.py", line 275, in call_function_local return pipe_caller(args, kwargs) File "/home/srd-user/workspace/mmlab_prj/mmdeploy/mmdeploy/apis/core/pipeline_manager.py", line 107, in call ret = func(*args, kwargs) File "/home/srd-user/workspace/mmlab_prj/mmdeploy/mmdeploy/apis/pytorch2onnx.py", line 98, in torch2onnx export( File "/home/srd-user/workspace/mmlab_prj/mmdeploy/mmdeploy/apis/core/pipeline_manager.py", line 356, in _wrap return self.call_function(funcname, *args, *kwargs) File "/home/srd-user/workspace/mmlab_prj/mmdeploy/mmdeploy/apis/core/pipeline_manager.py", line 326, in call_function return self.call_function_local(func_name, args, kwargs) File "/home/srd-user/workspace/mmlab_prj/mmdeploy/mmdeploy/apis/core/pipeline_manager.py", line 275, in call_function_local return pipe_caller(*args, kwargs) File "/home/srd-user/workspace/mmlab_prj/mmdeploy/mmdeploy/apis/core/pipeline_manager.py", line 107, in call ret = func(*args, *kwargs) File "/home/srd-user/workspace/mmlab_prj/mmdeploy/mmdeploy/apis/onnx/export.py", line 138, in export torch.onnx.export( File "/home/srd-user/.conda/envs/mmlab_dep_cu118/lib/python3.8/site-packages/torch/onnx/utils.py", line 516, in export _export( File "/home/srd-user/.conda/envs/mmlab_dep_cu118/lib/python3.8/site-packages/torch/onnx/utils.py", line 1596, in _export graph, params_dict, torch_out = _model_to_graph( File "/home/srd-user/workspace/mmlab_prj/mmdeploy/mmdeploy/apis/onnx/optimizer.py", line 27, in model_to_graph__custom_optimizer graph, params_dict, torch_out = ctx.origin_func(args, kwargs) File "/home/srd-user/.conda/envs/mmlab_dep_cu118/lib/python3.8/site-packages/torch/onnx/utils.py", line 1135, in _model_to_graph graph, params, torch_out, module = _create_jit_graph(model, args) File "/home/srd-user/.conda/envs/mmlab_dep_cu118/lib/python3.8/site-packages/torch/onnx/utils.py", line 1011, in _create_jit_graph graph, torch_out = _trace_and_get_graph_from_model(model, args) File "/home/srd-user/.conda/envs/mmlab_dep_cu118/lib/python3.8/site-packages/torch/onnx/utils.py", line 915, in _trace_and_get_graph_from_model trace_graph, torch_out, inputs_states = torch.jit._get_trace_graph( File "/home/srd-user/.conda/envs/mmlab_dep_cu118/lib/python3.8/site-packages/torch/jit/_trace.py", line 1285, in _get_trace_graph outs = ONNXTracedModule( File "/home/srd-user/.conda/envs/mmlab_dep_cu118/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1518, in _wrapped_call_impl return self._call_impl(*args, kwargs) File "/home/srd-user/.conda/envs/mmlab_dep_cu118/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1527, in _call_impl return forward_call(*args, kwargs) File "/home/srd-user/.conda/envs/mmlab_dep_cu118/lib/python3.8/site-packages/torch/jit/_trace.py", line 133, in forward graph, out = torch._C._create_graph_by_tracing( File "/home/srd-user/.conda/envs/mmlab_dep_cu118/lib/python3.8/site-packages/torch/jit/_trace.py", line 124, in wrapper outs.append(self.inner(trace_inputs)) File "/home/srd-user/.conda/envs/mmlab_dep_cu118/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1518, in _wrapped_call_impl return self._call_impl(args, kwargs) File "/home/srd-user/.conda/envs/mmlab_dep_cu118/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1527, in _call_impl return forward_call(*args, kwargs) File "/home/srd-user/.conda/envs/mmlab_dep_cu118/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1508, in _slow_forward result = self.forward(*input, kwargs) File "/home/srd-user/workspace/mmlab_prj/mmdeploy/mmdeploy/apis/onnx/export.py", line 123, in wrapper return forward(*arg, *kwargs) File "/home/srd-user/workspace/mmlab_prj/mmdeploy/mmdeploy/codebase/mmdet/models/detectors/base_detr.py", line 89, in detection_transformerforward return predict_impl(self, batch_inputs, data_samples, rescale) File "/home/srd-user/workspace/mmlab_prj/mmdeploy/mmdeploy/core/optimizers/function_marker.py", line 266, in g rets = f(args, kwargs) File "/home/srd-user/workspace/mmlab_prj/mmdeploy/mmdeploy/codebase/mmdet/models/detectors/base_detr.py", line 22, in __predict_impl head_inputs_dict = self.forward_transformer(img_feats, data_samples) File "/home/srd-user/.conda/envs/mmlab_dep_cu118/lib/python3.8/site-packages/mmdet/models/detectors/grounding_dino.py", line 152, in forward_transformer encoder_inputs_dict, decoder_inputs_dict = self.pre_transformer( File "/home/srd-user/.conda/envs/mmlab_dep_cu118/lib/python3.8/site-packages/mmdet/models/detectors/deformable_detr.py", line 152, in pre_transformer assert batch_data_samples is not None AssertionError (mmlab_dep_cu118) aaa-user@aaa-ubuntu-20:~/workspace/mmlab_prj/mmdeploy$

Reproduction

python tools/torch2onnx.py \ ${DEPLOY_CFG_PATH}/mmdet/detection/detection_onnxruntime_static.py \ ${MODEL_CFG_PATH}/grounding_dino/grounding_dino_swin-t_pretrain_obj365_goldg_cap4m.py \ ${MODEL_CHECKPOINT_PATH}/groundingdino_swint_ogc_mmdet-822d7e9d.pth \ ${INPUT_DIR}/images/firc_accident_5.jpg \ --work-dir ${WORK_DIR}/mmdeploy_models/mmdet/grounding_dino \ --device cpu \ --log-level INFO

Environment

(mmlab_dep_cu118) aaa@aaa-ubuntu-20:~/workspace/mmlab_prj/mmdeploy$ python ./tools/check_env.py 
03/12 11:32:28 - mmengine - INFO - 

03/12 11:32:28 - mmengine - INFO - **********Environmental information**********
03/12 11:32:32 - mmengine - INFO - sys.platform: linux
03/12 11:32:32 - mmengine - INFO - Python: 3.8.18 (default, Sep 11 2023, 13:40:15) [GCC 11.2.0]
03/12 11:32:32 - mmengine - INFO - CUDA available: True
03/12 11:32:32 - mmengine - INFO - numpy_random_seed: 2147483648
03/12 11:32:32 - mmengine - INFO - GPU 0,1: NVIDIA RTX A5000
03/12 11:32:32 - mmengine - INFO - CUDA_HOME: /usr/local/cuda
03/12 11:32:32 - mmengine - INFO - NVCC: Cuda compilation tools, release 11.8, V11.8.89
03/12 11:32:32 - mmengine - INFO - GCC: gcc (Ubuntu 9.4.0-1ubuntu1~20.04.3) 9.4.0
03/12 11:32:32 - mmengine - INFO - PyTorch: 2.1.0
03/12 11:32:32 - mmengine - INFO - PyTorch compiling details: PyTorch built with:
  - GCC 9.3
  - C++ Version: 201703
  - Intel(R) oneAPI Math Kernel Library Version 2023.1-Product Build 20230303 for Intel(R) 64 architecture applications
  - Intel(R) MKL-DNN v3.1.1 (Git Hash 64f6bcbcbab628e96f33a62c3e975f8535a7bde4)
  - OpenMP 201511 (a.k.a. OpenMP 4.5)
  - LAPACK is enabled (usually provided by MKL)
  - NNPACK is enabled
  - CPU capability usage: AVX2
  - CUDA Runtime 11.8
  - NVCC architecture flags: -gencode;arch=compute_50,code=sm_50;-gencode;arch=compute_60,code=sm_60;-gencode;arch=compute_61,code=sm_61;-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;-gencode;arch=compute_37,code=sm_37;-gencode;arch=compute_90,code=sm_90;-gencode;arch=compute_37,code=compute_37
  - CuDNN 8.7
  - Magma 2.6.1
  - Build settings: BLAS_INFO=mkl, BUILD_TYPE=Release, CUDA_VERSION=11.8, CUDNN_VERSION=8.7.0, CXX_COMPILER=/opt/rh/devtoolset-9/root/usr/bin/c++, CXX_FLAGS= -D_GLIBCXX_USE_CXX11_ABI=0 -fabi-version=11 -fvisibility-inlines-hidden -DUSE_PTHREADPOOL -DNDEBUG -DUSE_KINETO -DLIBKINETO_NOROCTRACER -DUSE_FBGEMM -DUSE_QNNPACK -DUSE_PYTORCH_QNNPACK -DUSE_XNNPACK -DSYMBOLICATE_MOBILE_DEBUG_HANDLE -O2 -fPIC -Wall -Wextra -Werror=return-type -Werror=non-virtual-dtor -Werror=bool-operation -Wnarrowing -Wno-missing-field-initializers -Wno-type-limits -Wno-array-bounds -Wno-unknown-pragmas -Wno-unused-parameter -Wno-unused-function -Wno-unused-result -Wno-strict-overflow -Wno-strict-aliasing -Wno-stringop-overflow -Wno-psabi -Wno-error=pedantic -Wno-error=old-style-cast -Wno-invalid-partial-specialization -Wno-unused-private-field -Wno-aligned-allocation-unavailable -Wno-missing-braces -fdiagnostics-color=always -faligned-new -Wno-unused-but-set-variable -Wno-maybe-uninitialized -fno-math-errno -fno-trapping-math -Werror=format -Werror=cast-function-type -Wno-stringop-overflow, LAPACK_INFO=mkl, PERF_WITH_AVX=1, PERF_WITH_AVX2=1, PERF_WITH_AVX512=1, TORCH_DISABLE_GPU_ASSERTS=ON, TORCH_VERSION=2.1.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, USE_ROCM=OFF, 

03/12 11:32:32 - mmengine - INFO - TorchVision: 0.16.0
03/12 11:32:32 - mmengine - INFO - OpenCV: 4.9.0
03/12 11:32:32 - mmengine - INFO - MMEngine: 0.10.2
03/12 11:32:32 - mmengine - INFO - MMCV: 2.1.0
03/12 11:32:32 - mmengine - INFO - MMCV Compiler: GCC 9.3
03/12 11:32:32 - mmengine - INFO - MMCV CUDA Compiler: 11.8
03/12 11:32:32 - mmengine - INFO - MMDeploy: 1.3.1+bc75c9d
03/12 11:32:32 - mmengine - INFO - 

03/12 11:32:32 - mmengine - INFO - **********Backend information**********
03/12 11:32:33 - mmengine - INFO - tensorrt:    8.6.1
03/12 11:32:33 - mmengine - INFO - tensorrt custom ops: Available
03/12 11:32:33 - mmengine - INFO - ONNXRuntime: 1.15.0
03/12 11:32:33 - mmengine - INFO - ONNXRuntime-gpu:     1.15.0
03/12 11:32:33 - mmengine - INFO - ONNXRuntime custom ops:      Available
03/12 11:32:33 - mmengine - INFO - pplnn:       None
03/12 11:32:33 - mmengine - INFO - ncnn:        None
03/12 11:32:33 - mmengine - INFO - snpe:        None
03/12 11:32:33 - mmengine - INFO - openvino:    None
03/12 11:32:33 - mmengine - INFO - torchscript: 2.1.0+cu118
03/12 11:32:33 - mmengine - INFO - torchscript custom ops:      NotAvailable
03/12 11:32:33 - mmengine - INFO - rknn-toolkit:        None
03/12 11:32:33 - mmengine - INFO - rknn-toolkit2:       None
03/12 11:32:33 - mmengine - INFO - ascend:      None
03/12 11:32:33 - mmengine - INFO - coreml:      None
03/12 11:32:33 - mmengine - INFO - tvm: None
03/12 11:32:33 - mmengine - INFO - vacc:        None
03/12 11:32:33 - mmengine - INFO - 

03/12 11:32:33 - mmengine - INFO - **********Codebase information**********
03/12 11:32:33 - mmengine - INFO - mmdet:       3.2.0
03/12 11:32:33 - mmengine - INFO - mmseg:       1.2.2
03/12 11:32:33 - mmengine - INFO - mmpretrain:  1.2.0
03/12 11:32:33 - mmengine - INFO - mmocr:       None
03/12 11:32:33 - mmengine - INFO - mmagic:      None
03/12 11:32:33 - mmengine - INFO - mmdet3d:     None
03/12 11:32:33 - mmengine - INFO - mmpose:      1.3.1
03/12 11:32:33 - mmengine - INFO - mmrotate:    None
03/12 11:32:33 - mmengine - INFO - mmaction:    1.2.0
03/12 11:32:33 - mmengine - INFO - mmrazor:     None
03/12 11:32:33 - mmengine - INFO - mmyolo:      None
(mmlab_dep_cu118) aaa@aaa-ubuntu-20:~/workspace/mmlab_prj/mmdeploy$

Error traceback

(mmlab_dep_cu118) aaa@aaa-ubuntu-20:~/workspace/mmlab_prj/mmdeploy$ python tools/torch2onnx.py \
>     ${DEPLOY_CFG_PATH}/mmdet/detection/detection_onnxruntime_static.py \
>     ${MODEL_CFG_PATH}/grounding_dino/grounding_dino_swin-t_pretrain_obj365_goldg_cap4m.py \
>     ${MODEL_CHECKPOINT_PATH}/groundingdino_swint_ogc_mmdet-822d7e9d.pth \
>     ${INPUT_DIR}/images/firc_accident_5.jpg \
>     --work-dir ${WORK_DIR}/mmdeploy_models/mmdet/grounding_dino \
>     --device cpu \
>     --log-level INFO
03/12 11:26:12 - mmengine - INFO - torch2onnx: 
        model_cfg: /home/srd-user/workspace/mmlab_prj/mmdetection/configs/grounding_dino/grounding_dino_swin-t_pretrain_obj365_goldg_cap4m.py 
        deploy_cfg: /home/srd-user/workspace/mmlab_prj/mmdeploy/configs/mmdet/detection/detection_onnxruntime_static.py
03/12 11:26:17 - mmengine - WARNING - Failed to search registry with scope "mmdet" in the "Codebases" registry tree. As a workaround, the current "Codebases" registry in "mmdeploy" is used to build instance. This may cause unexpected failure when running the built modules. Please check whether "mmdet" is a correct scope, or whether the registry is initialized.
03/12 11:26:17 - mmengine - WARNING - Failed to search registry with scope "mmdet" in the "mmdet_tasks" registry tree. As a workaround, the current "mmdet_tasks" registry in "mmdeploy" is used to build instance. This may cause unexpected failure when running the built modules. Please check whether "mmdet" is a correct scope, or whether the registry is initialized.
Loads checkpoint by local backend from path: /home/srd-user/workspace/mmlab_prj/mmdetection/checkpoint/groundingdino_swint_ogc_mmdet-822d7e9d.pth
The model and loaded state dict do not match exactly

unexpected key in source state_dict: language_model.language_backbone.body.model.embeddings.position_ids

missing keys in source state_dict: dn_query_generator.label_embedding.weight

03/12 11:26:41 - mmengine - WARNING - DeprecationWarning: get_onnx_config will be deprecated in the future. 
03/12 11:26:41 - mmengine - INFO - Export PyTorch model to ONNX: /home/srd-user/workspace/mmlab_prj/mmdetection/work_dirs/mmdeploy_models/mmdet/grounding_dino/end2end.onnx.
/home/srd-user/workspace/mmlab_prj/mmdeploy/mmdeploy/codebase/mmdet/models/detectors/base_detr.py:85: TracerWarning: Iterating over a tensor might cause the trace to be incorrect. Passing a tensor of different shape won't change the number of iterations executed (and might lead to errors or silently give incorrect results).
  img_shape = [int(val) for val in img_shape]
/home/srd-user/workspace/mmlab_prj/mmdeploy/mmdeploy/codebase/mmdet/models/detectors/base_detr.py:85: 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!
  img_shape = [int(val) for val in img_shape]
/home/srd-user/workspace/mmlab_prj/mmdeploy/mmdeploy/core/optimizers/function_marker.py:160: 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/srd-user/.conda/envs/mmlab_dep_cu118/lib/python3.8/site-packages/mmdet/models/layers/transformer/utils.py:167: TracerWarning: Converting a tensor to a Python float 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!
  output_h = math.ceil(input_h / stride_h)
/home/srd-user/.conda/envs/mmlab_dep_cu118/lib/python3.8/site-packages/mmdet/models/layers/transformer/utils.py:168: TracerWarning: Converting a tensor to a Python float 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!
  output_w = math.ceil(input_w / stride_w)
/home/srd-user/.conda/envs/mmlab_dep_cu118/lib/python3.8/site-packages/mmdet/models/layers/transformer/utils.py:169: 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!
  pad_h = max((output_h - 1) * stride_h +
/home/srd-user/.conda/envs/mmlab_dep_cu118/lib/python3.8/site-packages/mmdet/models/layers/transformer/utils.py:171: 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!
  pad_w = max((output_w - 1) * stride_w +
/home/srd-user/.conda/envs/mmlab_dep_cu118/lib/python3.8/site-packages/mmdet/models/layers/transformer/utils.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!
  if pad_h > 0 or pad_w > 0:
/home/srd-user/workspace/mmlab_prj/mmdeploy/mmdeploy/codebase/mmdet/models/backbones.py:189: 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!
  assert L == H * W, 'input feature has wrong size'
/home/srd-user/.conda/envs/mmlab_dep_cu118/lib/python3.8/site-packages/mmdet/models/backbones/swin.py:267: 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!
  B = int(windows.shape[0] / (H * W / window_size / window_size))
/home/srd-user/.conda/envs/mmlab_dep_cu118/lib/python3.8/site-packages/mmdet/models/layers/transformer/utils.py:414: 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!
  assert L == H * W, 'input feature has wrong size'
Traceback (most recent call last):
  File "tools/torch2onnx.py", line 85, in <module>
    main()
  File "tools/torch2onnx.py", line 47, in main
    torch2onnx(
  File "/home/srd-user/workspace/mmlab_prj/mmdeploy/mmdeploy/apis/core/pipeline_manager.py", line 356, in _wrap
    return self.call_function(func_name_, *args, **kwargs)
  File "/home/srd-user/workspace/mmlab_prj/mmdeploy/mmdeploy/apis/core/pipeline_manager.py", line 326, in call_function
    return self.call_function_local(func_name, *args, **kwargs)
  File "/home/srd-user/workspace/mmlab_prj/mmdeploy/mmdeploy/apis/core/pipeline_manager.py", line 275, in call_function_local
    return pipe_caller(*args, **kwargs)
  File "/home/srd-user/workspace/mmlab_prj/mmdeploy/mmdeploy/apis/core/pipeline_manager.py", line 107, in __call__
    ret = func(*args, **kwargs)
  File "/home/srd-user/workspace/mmlab_prj/mmdeploy/mmdeploy/apis/pytorch2onnx.py", line 98, in torch2onnx
    export(
  File "/home/srd-user/workspace/mmlab_prj/mmdeploy/mmdeploy/apis/core/pipeline_manager.py", line 356, in _wrap
    return self.call_function(func_name_, *args, **kwargs)
  File "/home/srd-user/workspace/mmlab_prj/mmdeploy/mmdeploy/apis/core/pipeline_manager.py", line 326, in call_function
    return self.call_function_local(func_name, *args, **kwargs)
  File "/home/srd-user/workspace/mmlab_prj/mmdeploy/mmdeploy/apis/core/pipeline_manager.py", line 275, in call_function_local
    return pipe_caller(*args, **kwargs)
  File "/home/srd-user/workspace/mmlab_prj/mmdeploy/mmdeploy/apis/core/pipeline_manager.py", line 107, in __call__
    ret = func(*args, **kwargs)
  File "/home/srd-user/workspace/mmlab_prj/mmdeploy/mmdeploy/apis/onnx/export.py", line 138, in export
    torch.onnx.export(
  File "/home/srd-user/.conda/envs/mmlab_dep_cu118/lib/python3.8/site-packages/torch/onnx/utils.py", line 516, in export
    _export(
  File "/home/srd-user/.conda/envs/mmlab_dep_cu118/lib/python3.8/site-packages/torch/onnx/utils.py", line 1596, in _export
    graph, params_dict, torch_out = _model_to_graph(
  File "/home/srd-user/workspace/mmlab_prj/mmdeploy/mmdeploy/apis/onnx/optimizer.py", line 27, in model_to_graph__custom_optimizer
    graph, params_dict, torch_out = ctx.origin_func(*args, **kwargs)
  File "/home/srd-user/.conda/envs/mmlab_dep_cu118/lib/python3.8/site-packages/torch/onnx/utils.py", line 1135, in _model_to_graph
    graph, params, torch_out, module = _create_jit_graph(model, args)
  File "/home/srd-user/.conda/envs/mmlab_dep_cu118/lib/python3.8/site-packages/torch/onnx/utils.py", line 1011, in _create_jit_graph
    graph, torch_out = _trace_and_get_graph_from_model(model, args)
  File "/home/srd-user/.conda/envs/mmlab_dep_cu118/lib/python3.8/site-packages/torch/onnx/utils.py", line 915, in _trace_and_get_graph_from_model
    trace_graph, torch_out, inputs_states = torch.jit._get_trace_graph(
  File "/home/srd-user/.conda/envs/mmlab_dep_cu118/lib/python3.8/site-packages/torch/jit/_trace.py", line 1285, in _get_trace_graph
    outs = ONNXTracedModule(
  File "/home/srd-user/.conda/envs/mmlab_dep_cu118/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1518, in _wrapped_call_impl
    return self._call_impl(*args, **kwargs)
  File "/home/srd-user/.conda/envs/mmlab_dep_cu118/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1527, in _call_impl
    return forward_call(*args, **kwargs)
  File "/home/srd-user/.conda/envs/mmlab_dep_cu118/lib/python3.8/site-packages/torch/jit/_trace.py", line 133, in forward
    graph, out = torch._C._create_graph_by_tracing(
  File "/home/srd-user/.conda/envs/mmlab_dep_cu118/lib/python3.8/site-packages/torch/jit/_trace.py", line 124, in wrapper
    outs.append(self.inner(*trace_inputs))
  File "/home/srd-user/.conda/envs/mmlab_dep_cu118/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1518, in _wrapped_call_impl
    return self._call_impl(*args, **kwargs)
  File "/home/srd-user/.conda/envs/mmlab_dep_cu118/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1527, in _call_impl
    return forward_call(*args, **kwargs)
  File "/home/srd-user/.conda/envs/mmlab_dep_cu118/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1508, in _slow_forward
    result = self.forward(*input, **kwargs)
  File "/home/srd-user/workspace/mmlab_prj/mmdeploy/mmdeploy/apis/onnx/export.py", line 123, in wrapper
    return forward(*arg, **kwargs)
  File "/home/srd-user/workspace/mmlab_prj/mmdeploy/mmdeploy/codebase/mmdet/models/detectors/base_detr.py", line 89, in detection_transformer__forward
    return __predict_impl(self, batch_inputs, data_samples, rescale)
  File "/home/srd-user/workspace/mmlab_prj/mmdeploy/mmdeploy/core/optimizers/function_marker.py", line 266, in g
    rets = f(*args, **kwargs)
  File "/home/srd-user/workspace/mmlab_prj/mmdeploy/mmdeploy/codebase/mmdet/models/detectors/base_detr.py", line 22, in __predict_impl
    head_inputs_dict = self.forward_transformer(img_feats, data_samples)
  File "/home/srd-user/.conda/envs/mmlab_dep_cu118/lib/python3.8/site-packages/mmdet/models/detectors/grounding_dino.py", line 152, in forward_transformer
    encoder_inputs_dict, decoder_inputs_dict = self.pre_transformer(
  File "/home/srd-user/.conda/envs/mmlab_dep_cu118/lib/python3.8/site-packages/mmdet/models/detectors/deformable_detr.py", line 152, in pre_transformer
    assert batch_data_samples is not None
AssertionError
(mmlab_dep_cu118) aaa-user@aaa-ubuntu-20:~/workspace/mmlab_prj/mmdeploy$
lxjhunan commented 3 months ago

你好,遇到了一样的问题,不知道是否已经解决。

hedgehoggy commented 2 months ago

Hello, I'm also experiencing this problem, has it been solved yet?