PINTO0309 / PINTO_model_zoo

A repository for storing models that have been inter-converted between various frameworks. Supported frameworks are TensorFlow, PyTorch, ONNX, OpenVINO, TFJS, TFTRT, TensorFlowLite (Float32/16/INT8), EdgeTPU, CoreML.
https://qiita.com/PINTO
MIT License
3.5k stars 566 forks source link

Unable to convert ONNX file to TensorRT #278

Closed kaleab-k closed 2 years ago

kaleab-k commented 2 years ago

Issue Type

Support, Others

OS

Ubuntu

OS architecture

aarch64

Programming Language

C++, Python

Framework

ONNX, TensorRT

Model name and Weights/Checkpoints URL

https://github.com/PINTO0309/PINTO_model_zoo/tree/main/165_RealtimeStereo

Description

I was trying to convert the RTStereo ONNX file to TensorRT on Jetson Xavier using play_with_tensorrt repo. However, I faced an issue with the Concat layers. Below is the log output.

Relevant Log Output

[08/12/2022-20:18:37] [W] [TRT] onnx2trt_utils.cpp:363: Your ONNX model has been generated with INT64 weights, while TensorRT does not natively support INT64. Attempting to cast down to INT32.
[08/12/2022-20:18:37] [W] [TRT] onnx2trt_utils.cpp:391: One or more weights outside the range of INT32 was clamped
[08/12/2022-20:18:37] [E] [TRT] ModelImporter.cpp:748: While parsing node number 125 [Concat -> "488"]:
[08/12/2022-20:18:37] [E] [TRT] ModelImporter.cpp:749: --- Begin node ---
[08/12/2022-20:18:37] [E] [TRT] ModelImporter.cpp:750: input: "482"
input: "487"
output: "488"
name: "Concat_261"
op_type: "Concat"
attribute {
  name: "axis"
  i: 4
  type: INT
}

[08/12/2022-20:18:37] [E] [TRT] ModelImporter.cpp:751: --- End node ---
[08/12/2022-20:18:37] [E] [TRT] ModelImporter.cpp:753: ERROR: onnx2trt_utils.cpp:334 In function convertAxis:
[8] Assertion failed: (axis >= 0 && axis <= nbDims) && "Axis must be in the range [0, nbDims]."
[ERR: InferenceHelperTensorRt][149] Failed to parse onnx file (../play_with_tensorrt/pj_tensorrt_depth_stereo_rtstereo/build/resource//model/rtstereonet_maxdisp192_480x640.onnx)[ERR: DepthStereoEngine][91] Inference helper is not created
Initialization Error

URL or source code for simple inference testing code

https://github.com/iwatake2222/play_with_tensorrt

PINTO0309 commented 2 years ago

It's a bug in TensorRT. Good luck. image

kaleab-k commented 2 years ago

Hi @PINTO0309, But there is no node 482 in the graph? Only the Unsqueeze node, i.e. 487 is connected to the highlighted Concat node. The conversion worked when I remove the Concat node but the resulting disparity is just black screen. Don't you think there might be an issue with the ONNX conversion? Thank you!

PINTO0309 commented 2 years ago

model_float32.onnx.zip

kaleab-k commented 2 years ago

Hi @PINTO0309,

It worked! Thank you so much! Can you please tell me how you exported it (fixed it)? I would also be very grateful if you can send me the model with 720x1280 resolution as an input.

Thanks a lot!

PINTO0309 commented 2 years ago

I commit all models in advance to allow any amount of conversion between frameworks.

python -m tf2onnx.convert \
--saved-model tensorflow-model-path \
--output model.onnx

image

kaleab-k commented 2 years ago

Hi @PINTO0309, Thank you! Is there any chance I can get the ONNX file with NCHW format? Thanks a lot!

PINTO0309 commented 2 years ago

https://github.com/PINTO0309/simple-onnx-processing-tools