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

onnx2trt error #244

Closed
MohamedAfifii opened this issue Feb 19, 2019 · 6 comments
Closed

onnx2trt error #244

MohamedAfifii opened this issue Feb 19, 2019 · 6 comments

Comments

@MohamedAfifii
Copy link

I exported vgg16 from keras as an onnx file:

onnx_model = onnxmltools.convert_keras(vgg)
onnxmltools.utils.save_model(onnx_model, 'vgg.onnx')

Then on a Jetson Tx2 I executed: onnx2trt vgg.onnx -o onnx.trt

This is what I got:

[libprotobuf ERROR google/protobuf/text_format.cc:307] Error parsing text-format onnx2trt_onnx.ModelProto: 1:1: Invalid control characters encountered in text.
[libprotobuf ERROR google/protobuf/text_format.cc:307] Error parsing text-format onnx2trt_onnx.ModelProto: 1:16: Invalid control characters encountered in text.
[libprotobuf ERROR google/protobuf/text_format.cc:307] Error parsing text-format onnx2trt_onnx.ModelProto: 1:21: Already saw decimal point or exponent; can't have another one.
[libprotobuf ERROR google/protobuf/text_format.cc:307] Error parsing text-format onnx2trt_onnx.ModelProto: 1:18: Message type "onnx2trt_onnx.ModelProto" has no field named "OnnxMLTools".
Failed to parse ONNX model
@vinitra-zz
Copy link
Member

Hello @MohamedAfifii! Thank you for reporting your experience.

  1. Can you try running converting the vgg16.onnx file directly from the ONNX model zoo to TensorRT using onnx2trt on your Jetson Tx2 machine?

  2. Please test your intermediate vgg.onnx file with expected inputs and outputs (in comparison to the original keras model) using onnxruntime.

This will help us to determine whether the error is due to the keras conversion process in onnxmltools or during the onnx2trt parsing and conversion (in which case it might make more sense to report this issue directly to those developers). Any model files you can provide would also be helpful.

@MohamedAfifii
Copy link
Author

Thank you for your reply @vinitra
The parser successfully converted the vgg16.onnx from the model zoo.
I uploaded the model that I exported from keras: link

@jiafatom
Copy link
Collaborator

@MohamedAfifii , can you try convert keras model using https://github.com/onnx/keras-onnx ?
There is a Readme there and we successfully convert vgg16 there.

@vinitra-zz
Copy link
Member

Thanks for the link @jiafatom!

@MohamedAfifii, please see the tutorial that David linked above. It provides code for successfully converting a keras model to onnx. I tried to open your attached model using onnx.load('vgg.onnx') and Netron and failed in both cases with a protobuf decoder error, pointing to an error somewhere in the conversion script or original keras model.

The following snippet creates a valid VGG16 ONNX model with keras2onnx 1.3.0 and onnxmltools 1.3.1.

import keras2onnx
import onnxmltools

from keras.applications.vgg16 import VGG16
model = VGG16(include_top=True, weights='imagenet')

onnx_model = keras2onnx.convert_keras(model, model.name)
onnxmltools.utils.save_model(onnx_model, 'vgg16.onnx')

@MohamedAfifii
Copy link
Author

MohamedAfifii commented Feb 24, 2019

Thank you,
Both keras2onnx and onnxmltools work now. When I exported the damaged vgg.onnx file I had different model objects instantiated and I was using Jupyter. I tried to replicate the error to know the exact reason but unfortunately I couldn't.
However I still get the following error:

WARNING: ONNX model has a newer ir_version (0.0.4) than this parser was built against (0.0.3).
Parsing model
While parsing node number 36 [Cast -> "flatten_imp_root__flatten_Shape__3_0"]:
ERROR: /usr/src/onnx-tensorrt/ModelImporter.cpp:142 In function importNode:
[8] No importer registered for op: Cast

But this error is not related to the keras to onnx conversion, it is a problem with keras' flatten layer which causes problem even with the UFF parser.

@DJMeng
Copy link

DJMeng commented Jul 17, 2019

@MohamedAfifii hi guys, i also meet the same problem:
[8] No importer registered for op: Cast
do you solve it? Please help me. Thanks first!

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

4 participants