SsisyphusTao / Pytorch-TensorRT-Plugins

Useful plugins for Pytorch1.5+ and TensorRT7/8.
37 stars 4 forks source link

IndexError: _Map_base::at #1

Open minhhoangbui opened 3 years ago

minhhoangbui commented 3 years ago

Thank you very much for your materials. I managed to use your pytorch dcn to train my model. However, when I convert this model to ONNX format, this error apprears. Do you know why?

  File "/data1/hoangbm/codes/CenterNet/src/lib/models/networks/dcnv2_torch15/dcn_v2_wrapper.py", line 105, in forward
    return DeformableConv2DFunction.apply(inputs, self.weight, self.bias, offset, mask, self.stride, self.pad, self.dilation, self.deformable_groups)
  File "/data1/hoangbm/codes/CenterNet/src/lib/models/networks/dcnv2_torch15/dcn_v2_wrapper.py", line 28, in forward
    ctx.deformable_groups
IndexError: _Map_base::at

This code produce this error

onnx.export(model, input_, '/data1/hoangbm/temp/pp_cnet15_dla.onnx', 
            keep_initializers_as_inputs=True,
            verbose=False, operator_export_type=OperatorExportTypes.ONNX)
SsisyphusTao commented 3 years ago

Thank you very much for your materials. I managed to use your pytorch dcn to train my model. However, when I convert this model to ONNX format, this error apprears. Do you know why?

  File "/data1/hoangbm/codes/CenterNet/src/lib/models/networks/dcnv2_torch15/dcn_v2_wrapper.py", line 105, in forward
    return DeformableConv2DFunction.apply(inputs, self.weight, self.bias, offset, mask, self.stride, self.pad, self.dilation, self.deformable_groups)
  File "/data1/hoangbm/codes/CenterNet/src/lib/models/networks/dcnv2_torch15/dcn_v2_wrapper.py", line 28, in forward
    ctx.deformable_groups
IndexError: _Map_base::at

This code produce this error

onnx.export(model, input_, '/data1/hoangbm/temp/pp_cnet15_dla.onnx', 
            keep_initializers_as_inputs=True,
            verbose=False, operator_export_type=OperatorExportTypes.ONNX)

I never used onnx to run models before, but as I as I know, if you want to use informal layers in onnx, you also need to write plugins like what i did to pytorch and tensorrt...

zengjie617789 commented 2 years ago

@SsisyphusTao , Could you explain how to implement the code of custom op in ONNX . As far as i am concerned, it just need to register the simbolic function through g.op() after we can use the register op in pytorch. I think there are there steps for custom ops:

  1. implement custom op operations in c++/cuda ;
  2. register the custom op in python code for the need of exporting onnx model;
  3. reigister the plugin in tensorrt-onnx so that it can find the register op when exporting engine file. if not, can you share the idea of the process? thank you in advance.