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

ONNX模型导入到TensorRT报错。 #26

Closed
saladjay opened this issue Oct 17, 2019 · 8 comments
Closed

ONNX模型导入到TensorRT报错。 #26

saladjay opened this issue Oct 17, 2019 · 8 comments

Comments

@saladjay
Copy link

saladjay commented Oct 17, 2019

image
模型是Mb_Tiny_RFB_FD_train_input_640.pth

@saladjay
Copy link
Author

一般情况下,ONNX导入到TensorRT报这个错误,是因为pytorch使用了view层。但是我去看代码,没有找出view层在哪里。

@Linzaer
Copy link
Owner

Linzaer commented Oct 18, 2019

compute_header里有view,你可以用onnx-simplifier 生成精简onnx试下。

@saladjay
Copy link
Author

image
我解决上面那个的问题,在compute_header中使用view(int(num1),num2)这种方式解决。
接下来slice操作报错了。slice对应pytorch的tensor取区间操作。我反复查看了pytorch的代码,没发现越界的问题。不知道怎么解决。

@saladjay
Copy link
Author

image
image

@Linzaer
Copy link
Owner

Linzaer commented Oct 18, 2019

@saladjay tensorRt没怎么用过,不过你说的这部分属于后处理代码部分,数学算子比较多一点,各个框架之间算子转换兼容性比较容易出问题。其实你可以在导出onnx的时候注释掉ssd.py中调用convert_locations_to_boxes()和center_form_to_corner_form()这两处,应该是第95~98行,让推理框架只负责提取特征,输出上面boxes偏移量就好,框解码部分的后处理代码可以用c++写,不是很复杂,可控速度也不慢优化程度高。而且推理框架处理这段可能效果反而不太好,不太可控。

@saladjay
Copy link
Author

saladjay commented Oct 19, 2019

image
像这种就能成功pytorch->onnx->tensorRT,截取的区间不要是最后一个维度。同时在pytorch->onnx的过程中最好不要使用像[:,0:2,:]的操作,除了batch,最好每个维度都给出确定的数字。希望能帮到同样像导出tensorRT的人。

@Linzaer Linzaer closed this as completed Oct 20, 2019
@atanx
Copy link

atanx commented Oct 21, 2019

image
像这种就能成功pytorch->onnx->tensorRT,截取的区间不要是最后一个维度。同时在pytorch->onnx的过程中最好不要使用像[:,0:2,:]的操作,除了batch,最好每个维度都给出确定的数字。希望能帮到同样像导出tensorRT的人。

遇到一样的问题。

In node 76 (convert_axis): UNSUPPORTED_NODE: Assertion failed: axis >= 0 && axis < nbDims

能详细讲一下怎么转tensorrt模型吗?

@saladjay
Copy link
Author

像这种就能成功pytorch->onnx->tensorRT,截取的区间不要是最后一个维度。同时在pytorch->onnx的过程中最好不要使用像[:,0:2,:]的操作,除了batch,最好每个维度都给出确定的数字。希望能帮到同样像导出tensorRT的人。

遇到一样的问题。
In node 76 (convert_axis): UNSUPPORTED_NODE: Assertion failed: axis >= 0 && axis < nbDims

能详细讲一下怎么转tensorrt模型吗?

view改flatten或者view的第一个参数强制转换为int类型

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants