mmdeploy icon indicating copy to clipboard operation
mmdeploy copied to clipboard

[Bug] Faster-RCNN Conversion to ncnn causes exception

Open rohansaw opened this issue 1 year ago • 0 comments

Checklist

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

Describe the bug

I am trying to convert my fine-tuned faster-rcnn-resnext101 model to ncnn. When I convert the model to ONNX this works and the validation results also look good. However, if I try to convert it to ncnn using tools/deploy.py, I get the following error during conversion: RuntimeError: Sizes of tensors must match except in dimension 2. Expected size 1 but got size 1000 for tensor number 1 in the list.

I also get the warning: Can not find mmdet.models.dense_heads.RPNHead.get_bboxes, function rewrite will not be applied

Reproduction

  1. I am running tools/deploy.py with the following deploy and model config and the path to the pytorch model.

My deploy config file: _base_ = ['/root/workspace/mmdeploy/configs/mmdet/_base_/base_static.py', '/root/workspace/mmdeploy/configs/_base_/backends/ncnn.py'] onnx_config = dict(output_names=['detection_output'], input_shape=[2688,1512])

I also tried adding: partition_config = dict(type='two_stage', apply_marks=True), however with no change.

My model config file: auto_scale_lr = dict(base_batch_size=16, enable=False) backend_args = None batch_size = 1 classes = ('boat', ) data_preprocessor = dict( bgr_to_rgb=True, mean=[ 70.4055, 108.4005, 143.922, ], pad_size_divisor=32, std=[ 52.529999999999994, 47.532000000000004, 56.559, ], type='mmdet.DetDataPreprocessor') data_root = '/data/sw/coco' dataset_type = 'CocoDataset' default_hooks = dict( checkpoint=dict( interval=1, rule='greater', save_best='coco/bbox_mAP', type='CheckpointHook'), logger=dict(interval=50, type='LoggerHook'), param_scheduler=dict(type='ParamSchedulerHook'), sampler_seed=dict(type='DistSamplerSeedHook'), timer=dict(type='IterTimerHook'), visualization=dict(type='DetVisualizationHook')) default_scope = 'mmdet' ds_name = 'sw' env_cfg = dict( cudnn_benchmark=False, dist_cfg=dict(backend='nccl'), mp_cfg=dict(mp_start_method='fork', opencv_num_threads=0)) img_size = ( 2688, 1512, ) launcher = 'none' load_from = '/data/results/faster_rcnn_resnet101/sw/best_coco_bbox_mAP_epoch_2.pth' log_level = 'INFO' log_processor = dict(by_epoch=True, type='LogProcessor', window_size=50) mean = [ 70.4055, 108.4005, 143.922, ] model = dict( backbone=dict( base_width=4, depth=101, frozen_stages=1, groups=64, init_cfg=dict( checkpoint='open-mmlab://resnext101_64x4d', type='Pretrained'), norm_cfg=dict(requires_grad=True, type='BN'), norm_eval=True, num_stages=4, out_indices=( 0, 1, 2, 3, ), style='pytorch', type='ResNeXt'), data_preprocessor=dict( bgr_to_rgb=True, mean=[ 70.4055, 108.4005, 143.922, ], pad_size_divisor=32, std=[ 52.529999999999994, 47.532000000000004, 56.559, ], type='mmdet.DetDataPreprocessor'), neck=dict( in_channels=[ 256, 512, 1024, 2048, ], num_outs=5, out_channels=256, type='FPN'), roi_head=dict( bbox_head=dict( bbox_coder=dict( target_means=[ 0.0, 0.0, 0.0, 0.0, ], target_stds=[ 0.1, 0.1, 0.2, 0.2, ], type='DeltaXYWHBBoxCoder'), fc_out_channels=1024, in_channels=256, loss_bbox=dict(loss_weight=1.0, type='L1Loss'), loss_cls=dict( loss_weight=1.0, type='CrossEntropyLoss', use_sigmoid=False), num_classes=1, reg_class_agnostic=False, roi_feat_size=7, type='Shared2FCBBoxHead'), bbox_roi_extractor=dict( featmap_strides=[ 4, 8, 16, 32, ], out_channels=256, roi_layer=dict(output_size=7, sampling_ratio=0, type='RoIAlign'), type='SingleRoIExtractor'), type='StandardRoIHead'), rpn_head=dict( anchor_generator=dict( ratios=[ 0.5, 1.0, 2.0, ], scales=[ 4, ], strides=[ 4, 8, 16, 32, 64, ], type='AnchorGenerator'), bbox_coder=dict( target_means=[ 0.0, 0.0, 0.0, 0.0, ], target_stds=[ 1.0, 1.0, 1.0, 1.0, ], type='DeltaXYWHBBoxCoder'), feat_channels=256, in_channels=256, loss_bbox=dict(loss_weight=1.0, type='L1Loss'), loss_cls=dict( loss_weight=1.0, type='CrossEntropyLoss', use_sigmoid=True), type='RPNHead'), test_cfg=dict( rcnn=dict( max_per_img=100, nms=dict(iou_threshold=0.5, type='nms'), score_thr=0.05), rpn=dict( max_per_img=1000, min_bbox_size=0, nms=dict(iou_threshold=0.7, type='nms'), nms_pre=1000)), train_cfg=dict( rcnn=dict( assigner=dict( ignore_iof_thr=-1, match_low_quality=False, min_pos_iou=0.5, neg_iou_thr=0.5, pos_iou_thr=0.5, type='MaxIoUAssigner'), debug=False, pos_weight=-1, sampler=dict( add_gt_as_proposals=True, neg_pos_ub=-1, num=512, pos_fraction=0.25, type='RandomSampler')), rpn=dict( allowed_border=-1, assigner=dict( ignore_iof_thr=-1, match_low_quality=True, min_pos_iou=0.3, neg_iou_thr=0.3, pos_iou_thr=0.7, type='MaxIoUAssigner'), debug=False, pos_weight=-1, sampler=dict( add_gt_as_proposals=False, neg_pos_ub=-1, num=256, pos_fraction=0.5, type='RandomSampler')), rpn_proposal=dict( max_per_img=1000, min_bbox_size=0, nms=dict(iou_threshold=0.7, type='nms'), nms_pre=2000)), type='FasterRCNN') num_classes = 1 optim_wrapper = dict( optimizer=dict( lr=0.001, momentum=0.9, nesterov=True, type='SGD', weight_decay=0.0001), type='OptimWrapper') param_scheduler = [ dict( begin=0, by_epoch=False, end=500, start_factor=0.001, type='LinearLR'), dict( begin=0, by_epoch=True, end=12, gamma=0.1, milestones=[ 8, 11, ], type='MultiStepLR'), ] resume = False std = [ 52.529999999999994, 47.532000000000004, 56.559, ] test_cfg = dict(type='TestLoop') test_dataloader = dict( batch_size=1, dataset=dict( ann_file='annotations/instances_val.json', backend_args=None, data_prefix=dict(img='val'), data_root='/data/sw/coco', metainfo=dict(classes=('boat', )), pipeline=[ dict(backend_args=None, type='LoadImageFromFile'), dict(keep_ratio=True, scale=( 2688, 1512, ), type='Resize'), dict(type='LoadAnnotations', with_bbox=True), dict( meta_keys=( 'img_id', 'img_path', 'ori_shape', 'img_shape', 'scale_factor', ), type='PackDetInputs'), ], test_mode=True, type='CocoDataset'), drop_last=False, num_workers=8, persistent_workers=True, sampler=dict(shuffle=False, type='DefaultSampler')) test_evaluator = dict( ann_file='/data/sw/coco/annotations/instances_val.json', backend_args=None, classwise=True, format_only=False, metric='bbox', proposal_nums=( 1, 10, 100, 300, 1000, ), type='CocoMetric', use_mp_eval=True) test_pipeline = [ dict(backend_args=None, type='LoadImageFromFile'), dict(keep_ratio=True, scale=( 2688, 1512, ), type='Resize'), dict(type='LoadAnnotations', with_bbox=True), dict( meta_keys=( 'img_id', 'img_path', 'ori_shape', 'img_shape', 'scale_factor', ), type='PackDetInputs'), ] train_cfg = dict(max_epochs=2, type='EpochBasedTrainLoop', val_interval=1) train_dataloader = dict( batch_sampler=dict(type='AspectRatioBatchSampler'), batch_size=1, dataset=dict( ann_file='annotations/instances_train.json', backend_args=None, data_prefix=dict(img='train'), data_root='/data/sw/coco', filter_cfg=dict(filter_empty_gt=False, min_size=32), metainfo=dict(classes=('boat', )), pipeline=[ dict(backend_args=None, type='LoadImageFromFile'), dict(type='LoadAnnotations', with_bbox=True), dict(keep_ratio=True, scale=( 2688, 1512, ), type='Resize'), dict(prob=0.5, type='RandomFlip'), dict(type='PackDetInputs'), ], type='CocoDataset'), num_workers=8, persistent_workers=True, sampler=dict(shuffle=True, type='DefaultSampler')) train_json = 'annotations/instances_train.json' train_pipeline = [ dict(backend_args=None, type='LoadImageFromFile'), dict(type='LoadAnnotations', with_bbox=True), dict(keep_ratio=True, scale=( 2688, 1512, ), type='Resize'), dict(prob=0.5, type='RandomFlip'), dict(type='PackDetInputs'), ] train_prefix = 'train' val_cfg = dict(type='ValLoop') val_dataloader = dict( batch_size=1, dataset=dict( ann_file='annotations/instances_val.json', backend_args=None, data_prefix=dict(img='val'), data_root='/data/sw/coco', metainfo=dict(classes=('boat', )), pipeline=[ dict(backend_args=None, type='LoadImageFromFile'), dict(keep_ratio=True, scale=( 2688, 1512, ), type='Resize'), dict(type='LoadAnnotations', with_bbox=True), dict( meta_keys=( 'img_id', 'img_path', 'ori_shape', 'img_shape', 'scale_factor', ), type='PackDetInputs'), ], test_mode=True, type='CocoDataset'), drop_last=False, num_workers=8, persistent_workers=True, sampler=dict(shuffle=False, type='DefaultSampler')) val_evaluator = dict( ann_file='/data/sw/coco/annotations/instances_val.json', backend_args=None, classwise=True, format_only=False, metric='bbox', proposal_nums=( 1, 10, 100, 300, 1000, ), type='CocoMetric', use_mp_eval=True) val_json = 'annotations/instances_val.json' val_prefix = 'val' vis_backends = [ dict(type='LocalVisBackend'), dict( init_kwargs=dict(group='frcnn_sw', project='mmdetection'), type='WandbVisBackend'), ] visualizer = dict( name='visualizer', type='DetLocalVisualizer', vis_backends=[ dict(type='LocalVisBackend'), dict( init_kwargs=dict(group='frcnn_sw', project='mmdetection'), type='WandbVisBackend'), ]) work_dir = '/data/results/faster_rcnn_resnet101/sw'

Environment

02/19 10:36:58 - mmengine - INFO - **********Environmental information**********
02/19 10:36:59 - mmengine - INFO - sys.platform: linux
02/19 10:36:59 - mmengine - INFO - Python: 3.8.10 (default, May 26 2023, 14:05:08) [GCC 9.4.0]
02/19 10:36:59 - mmengine - INFO - CUDA available: True
02/19 10:36:59 - mmengine - INFO - MUSA available: False
02/19 10:36:59 - mmengine - INFO - numpy_random_seed: 2147483648
02/19 10:36:59 - mmengine - INFO - GPU 0: NVIDIA GeForce RTX 3090
02/19 10:36:59 - mmengine - INFO - CUDA_HOME: /usr/local/cuda
02/19 10:36:59 - mmengine - INFO - NVCC: Cuda compilation tools, release 11.8, V11.8.89
02/19 10:36:59 - mmengine - INFO - GCC: x86_64-linux-gnu-gcc (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0
02/19 10:36:59 - mmengine - INFO - PyTorch: 2.0.0+cu118
02/19 10:36:59 - mmengine - INFO - PyTorch compiling details: PyTorch built with:
  - GCC 9.3
  - C++ Version: 201703
  - Intel(R) oneAPI Math Kernel Library Version 2022.2-Product Build 20220804 for Intel(R) 64 architecture applications
  - Intel(R) MKL-DNN v2.7.3 (Git Hash 6dbeffbae1f23cbbeae17adb7b5b13f1f37c080e)
  - 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_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;-gencode;arch=compute_90,code=sm_90
  - 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 -Wno-deprecated -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 -Wunused-local-typedefs -Wno-unused-parameter -Wno-unused-function -Wno-unused-result -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 -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.0.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=1, USE_NNPACK=ON, USE_OPENMP=ON, USE_ROCM=OFF, 

02/19 10:36:59 - mmengine - INFO - TorchVision: 0.15.0+cu118
02/19 10:36:59 - mmengine - INFO - OpenCV: 4.5.4
02/19 10:36:59 - mmengine - INFO - MMEngine: 0.10.3
02/19 10:36:59 - mmengine - INFO - MMCV: 2.1.0
02/19 10:36:59 - mmengine - INFO - MMCV Compiler: GCC 9.3
02/19 10:36:59 - mmengine - INFO - MMCV CUDA Compiler: 11.8
02/19 10:36:59 - mmengine - INFO - MMDeploy: 1.3.1+bc75c9d
02/19 10:36:59 - mmengine - INFO - 

02/19 10:36:59 - mmengine - INFO - **********Backend information**********
02/19 10:36:59 - mmengine - INFO - tensorrt:    8.6.1
02/19 10:36:59 - mmengine - INFO - tensorrt custom ops: Available
02/19 10:36:59 - mmengine - INFO - ONNXRuntime: None
02/19 10:36:59 - mmengine - INFO - ONNXRuntime-gpu:     1.15.1
02/19 10:36:59 - mmengine - INFO - ONNXRuntime custom ops:      Available
02/19 10:36:59 - mmengine - INFO - pplnn:       0.8.1
02/19 10:36:59 - mmengine - INFO - ncnn:        1.0.20230905
02/19 10:36:59 - mmengine - INFO - ncnn custom ops:     Available
02/19 10:36:59 - mmengine - INFO - snpe:        None
02/19 10:36:59 - mmengine - INFO - openvino:    2023.0.2
02/19 10:36:59 - mmengine - INFO - torchscript: 2.0.0+cu118
02/19 10:36:59 - mmengine - INFO - torchscript custom ops:      Available
02/19 10:36:59 - mmengine - INFO - rknn-toolkit:        None
02/19 10:36:59 - mmengine - INFO - rknn-toolkit2:       None
02/19 10:36:59 - mmengine - INFO - ascend:      None
02/19 10:36:59 - mmengine - INFO - coreml:      None
02/19 10:36:59 - mmengine - INFO - tvm: None
02/19 10:36:59 - mmengine - INFO - vacc:        None
02/19 10:36:59 - mmengine - INFO - 

02/19 10:36:59 - mmengine - INFO - **********Codebase information**********
02/19 10:36:59 - mmengine - INFO - mmdet:       3.3.0
02/19 10:36:59 - mmengine - INFO - mmseg:       None
02/19 10:36:59 - mmengine - INFO - mmpretrain:  None
02/19 10:36:59 - mmengine - INFO - mmocr:       None
02/19 10:36:59 - mmengine - INFO - mmagic:      None
02/19 10:36:59 - mmengine - INFO - mmdet3d:     None
02/19 10:36:59 - mmengine - INFO - mmpose:      None
02/19 10:36:59 - mmengine - INFO - mmrotate:    None
02/19 10:36:59 - mmengine - INFO - mmaction:    None
02/19 10:36:59 - mmengine - INFO - mmrazor:     None
02/19 10:36:59 - mmengine - INFO - mmyolo:      None

Error traceback

`
02/19 08:08:31 - mmengine - INFO - Start pipeline mmdeploy.apis.pytorch2onnx.torch2onnx in subprocess
02/19 08:08:31 - 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.
02/19 08:08:31 - 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: /data/results/faster_rcnn_resnet101/sw/best_coco_bbox_mAP_epoch_2.pth
02/19 08:08:32 - mmengine - WARNING - DeprecationWarning: get_onnx_config will be deprecated in the future. 
02/19 08:08:32 - mmengine - INFO - Export PyTorch model to ONNX: /root/workspace/mmdeploy/end2end.onnx.
02/19 08:08:32 - mmengine - WARNING - Can not find torch.nn.functional.scaled_dot_product_attention, function rewrite will not be applied
02/19 08:08:32 - mmengine - WARNING - Can not find torch._C._jit_pass_onnx_autograd_function_process, function rewrite will not be applied
02/19 08:08:32 - mmengine - WARNING - Can not find mmdet.models.dense_heads.RPNHead.get_bboxes, function rewrite will not be applied
/root/workspace/mmdeploy/mmdeploy/codebase/mmdet/models/detectors/two_stage.py:71: 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]
/root/workspace/mmdeploy/mmdeploy/codebase/mmdet/models/detectors/two_stage.py:71: 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]
/root/workspace/mmdeploy/mmdeploy/pytorch/functions/getattribute.py:19: 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!
  ret = torch.Size([int(s) for s in ret])
/opt/conda/lib/python3.8/site-packages/mmdet/models/dense_heads/anchor_head.py:115: UserWarning: DeprecationWarning: anchor_generator is deprecated, please use "prior_generator" instead
  warnings.warn('DeprecationWarning: anchor_generator is deprecated, '
/opt/conda/lib/python3.8/site-packages/mmdet/models/task_modules/prior_generators/anchor_generator.py:356: UserWarning: ``grid_anchors`` would be deprecated soon. Please use ``grid_priors`` 
  warnings.warn('``grid_anchors`` would be deprecated soon. '
/opt/conda/lib/python3.8/site-packages/mmdet/models/task_modules/prior_generators/anchor_generator.py:392: UserWarning: ``single_level_grid_anchors`` would be deprecated soon. Please use ``single_level_grid_priors`` 
  warnings.warn(
/root/workspace/mmdeploy/mmdeploy/pytorch/functions/size.py:23: 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!
  ret = [int(r) for r in ret]
/root/workspace/mmdeploy/mmdeploy/pytorch/functions/topk.py:28: TracerWarning: torch.tensor results are registered as constants in the trace. You can safely ignore this warning if you use this function to create tensors out of constant variables that would be the same every time you call this function. In any other case, this might cause the trace to be incorrect.
  k = torch.tensor(k, device=input.device, dtype=torch.long)
/root/workspace/mmdeploy/mmdeploy/pytorch/functions/size.py:19: 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!
  ret = int(ret)
/root/workspace/mmdeploy/mmdeploy/mmcv/ops/nms.py:327: TracerWarning: torch.tensor results are registered as constants in the trace. You can safely ignore this warning if you use this function to create tensors out of constant variables that would be the same every time you call this function. In any other case, this might cause the trace to be incorrect.
  iou_threshold = torch.tensor([iou_threshold], dtype=torch.float32)
/root/workspace/mmdeploy/mmdeploy/mmcv/ops/nms.py:328: TracerWarning: torch.tensor results are registered as constants in the trace. You can safely ignore this warning if you use this function to create tensors out of constant variables that would be the same every time you call this function. In any other case, this might cause the trace to be incorrect.
  score_threshold = torch.tensor([score_threshold], dtype=torch.float32)
/root/workspace/mmdeploy/mmdeploy/mmcv/ops/nms.py:45: 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!
  score_threshold = float(score_threshold)
/root/workspace/mmdeploy/mmdeploy/mmcv/ops/nms.py:46: 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!
  iou_threshold = float(iou_threshold)
/opt/conda/lib/python3.8/site-packages/mmcv/ops/nms.py:30: 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 max_num > 0:
Process Process-2:
Traceback (most recent call last):
  File "/opt/conda/lib/python3.8/multiprocessing/process.py", line 315, in _bootstrap
    self.run()
  File "/opt/conda/lib/python3.8/multiprocessing/process.py", line 108, in run
    self._target(*self._args, **self._kwargs)
  File "/root/workspace/mmdeploy/mmdeploy/apis/core/pipeline_manager.py", line 107, in __call__
    ret = func(*args, **kwargs)
  File "/root/workspace/mmdeploy/mmdeploy/apis/pytorch2onnx.py", line 98, in torch2onnx
    export(
  File "/root/workspace/mmdeploy/mmdeploy/apis/core/pipeline_manager.py", line 356, in _wrap
    return self.call_function(func_name_, *args, **kwargs)
  File "/root/workspace/mmdeploy/mmdeploy/apis/core/pipeline_manager.py", line 326, in call_function
    return self.call_function_local(func_name, *args, **kwargs)
  File "/root/workspace/mmdeploy/mmdeploy/apis/core/pipeline_manager.py", line 275, in call_function_local
    return pipe_caller(*args, **kwargs)
  File "/root/workspace/mmdeploy/mmdeploy/apis/core/pipeline_manager.py", line 107, in __call__
    ret = func(*args, **kwargs)
  File "/root/workspace/mmdeploy/mmdeploy/apis/onnx/export.py", line 138, in export
    torch.onnx.export(
  File "/opt/conda/lib/python3.8/site-packages/torch/onnx/__init__.py", line 316, in export
    return utils.export(model, args, f, export_params, verbose, training,
  File "/opt/conda/lib/python3.8/site-packages/torch/onnx/utils.py", line 107, in export
    _export(model, args, f, export_params, verbose, training, input_names, output_names,
  File "/opt/conda/lib/python3.8/site-packages/torch/onnx/utils.py", line 724, in _export
    _model_to_graph(model, args, verbose, input_names,
  File "/root/workspace/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 "/opt/conda/lib/python3.8/site-packages/torch/onnx/utils.py", line 493, in _model_to_graph
    graph, params, torch_out, module = _create_jit_graph(model, args)
  File "/opt/conda/lib/python3.8/site-packages/torch/onnx/utils.py", line 437, in _create_jit_graph
    graph, torch_out = _trace_and_get_graph_from_model(model, args)
  File "/opt/conda/lib/python3.8/site-packages/torch/onnx/utils.py", line 388, in _trace_and_get_graph_from_model
    torch.jit._get_trace_graph(model, args, strict=False, _force_outplace=False, _return_inputs_states=True)
  File "/opt/conda/lib/python3.8/site-packages/torch/jit/_trace.py", line 1166, in _get_trace_graph
    outs = ONNXTracedModule(f, strict, _force_outplace, return_inputs, _return_inputs_states)(*args, **kwargs)
  File "/opt/conda/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1102, in _call_impl
    return forward_call(*input, **kwargs)
  File "/opt/conda/lib/python3.8/site-packages/torch/jit/_trace.py", line 127, in forward
    graph, out = torch._C._create_graph_by_tracing(
  File "/opt/conda/lib/python3.8/site-packages/torch/jit/_trace.py", line 118, in wrapper
    outs.append(self.inner(*trace_inputs))
  File "/opt/conda/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1102, in _call_impl
    return forward_call(*input, **kwargs)
  File "/opt/conda/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1090, in _slow_forward
    result = self.forward(*input, **kwargs)
  File "/root/workspace/mmdeploy/mmdeploy/apis/onnx/export.py", line 123, in wrapper
    return forward(*arg, **kwargs)
  File "/root/workspace/mmdeploy/mmdeploy/codebase/mmdet/models/detectors/two_stage.py", line 90, in two_stage_detector__forward
    output = self.roi_head.predict(
  File "/opt/conda/lib/python3.8/site-packages/mmdet/models/roi_heads/base_roi_head.py", line 118, in predict
    results_list = self.predict_bbox(
  File "/root/workspace/mmdeploy/mmdeploy/codebase/mmdet/models/roi_heads/standard_roi_head.py", line 45, in standard_roi_head__predict_bbox
    rois = torch.cat([batch_index, rois[..., :rois_dims - 1]], dim=-1)
RuntimeError: Sizes of tensors must match except in dimension 2. Expected size 1 but got size 1000 for tensor number 1 in the list.
02/19 08:08:50 - mmengine - ERROR - /root/workspace/mmdeploy/mmdeploy/apis/core/pipeline_manager.py - pop_mp_output - 80 - `mmdeploy.apis.pytorch2onnx.torch2onnx` with Call id: 0 failed. exit.
`

rohansaw avatar Feb 19 '24 10:02 rohansaw