CoDet icon indicating copy to clipboard operation
CoDet copied to clipboard

how to convet torch to onnx and then tensorrt

Open kkeono2 opened this issue 2 years ago • 4 comments

Thank you for your great work.

Do you have any plan to support model conveting implementation for onnx ?

kkeono2 avatar Nov 16 '23 09:11 kkeono2

Hi,

You can use detectron2's built-in script to export the model to onnx. Also, since this codebase is built upon Detic, I believe related discussions in their Issue #61 and #107 may help you.

codet-ovd avatar Nov 16 '23 12:11 codet-ovd

you can look at this discussion -> https://github.com/facebookresearch/Detic/issues/113#issue-1997887378

gigasurgeon avatar Nov 16 '23 22:11 gigasurgeon

Thanky you for rapid answering @codet-ovd

I used detectron2's built-in script (i just change set-up configuration in export_onnx.py ) to convert torch model to onnx and i have successfully converted. However, i faced the problem with topk initialization when i converted onnx to tensorrt as below(TensorRT error message). ''' [6] Invalid Node - /proposal_generator/TopK
This version of TensorRT only supports input K as an initializer '''

I guess the problem with topk initialization due to varing the image_thresh per image in centernet.py. Therefore, i fixed the image_thresh as constant value(0.1).

            if num_dets > post_nms_topk:
                cls_scores = result.scores
                # image_thresh, _ = torch.kthvalue(cls_scores.float().cpu(),num_dets - post_nms_topk + 1)
                keep = cls_scores >= 0.1 #image_thresh.item()  

I also faced the error as below. i don't know why these error is occuring. ''' [6] Invalid Node - /roi_heads/box_pooler/level_poolers.0/If /roi_heads/box_pooler/level_poolers.0/If_OutputLayer: IIfConditionalOutputLayer inputs must have the same shape. '''

Can you help me solve this please? I use TensorRT 8.5.1, ONNX 1.12.0

kkeono2 avatar Nov 17 '23 00:11 kkeono2

Thank you for answering @gigasurgeon

I can convert torch model to onnx without comment the nms_and_topk line in centernet, while exporting the model.

Actually, i can't convet onnx to tensorrt as above issue.

Can you give me a suggetion to solve above issue ?

kkeono2 avatar Nov 17 '23 00:11 kkeono2