keras-onnx icon indicating copy to clipboard operation
keras-onnx copied to clipboard

hi,I use keras2onnx to transfer keras_based network,then transfer onnx to tensorrt.when parsing with tensorrt,error shows like:netwokr layers=0!do you know why is it?

Open zlpson opened this issue 4 years ago • 17 comments

zlpson avatar Dec 25 '20 12:12 zlpson

code like this: from keras.models import load_model model = load_model('logs/multiBands/testKeras/last1.hdf5' )

onnx_model = keras2onnx.convert_keras(model, model.name) temp_model_file = 'conv_hdf5.onnx' onnx.save_model(onnx_model, temp_model_file)

zlpson avatar Dec 25 '20 12:12 zlpson

Is the onnx model itself working? If it does, then it should not be keras2onnx issue.

jiafatom avatar Dec 28 '20 04:12 jiafatom

can you show me how to prove the onnx model itself is working?

zlpson avatar Dec 28 '20 05:12 zlpson

Is the onnx model itself working? If it does, then it should not be keras2onnx issue.

can you show me how to prove the onnx model itself is working?

zlpson avatar Dec 28 '20 05:12 zlpson

We have many examples in our tests, does the onnx model run successfully using onnxruntime?

jiafatom avatar Dec 28 '20 05:12 jiafatom

We have many examples in our tests, does the onnx model run successfully using onnxruntime?

I put a png named 00003.png and run run_image in test_utils.py like this,but the output in NONE,Are you sure what the problem is?

from keras.applications.resnet50 import ResNet50 model = ResNet50(include_top=True, weights='imagenet') run_image(model,'./logs','./00003.png')

zlpson avatar Dec 28 '20 06:12 zlpson

We have many examples in our tests, does the onnx model run successfully using onnxruntime?

or can you show me the details for running the examples in tests?

zlpson avatar Dec 28 '20 07:12 zlpson

test_utils is the utility file. In applications/nightly_build, there are many examples there. Many are computer vision related models.

jiafatom avatar Dec 28 '20 16:12 jiafatom

test_utils is the utility file. In applications/nightly_build, there are many examples there. Many are computer vision related models.

I run test_deeplab_v3.py in applications/nightly_build,the output is like this: Ran 1 test in 0.009s OK (skipped=1) Skipped: DeeplabV3 is not supported for opset < 11.

is it normal?

zlpson avatar Dec 29 '20 02:12 zlpson

This is probably because you are using old onnx package. Try onnx==1.7.0. You can also set target_opset=12 in convert_keras function.

Here is an example for ResNet50.

jiafatom avatar Dec 29 '20 03:12 jiafatom

This is probably because you are using old onnx package. Try onnx==1.7.0. You can also set target_opset=12 in convert_keras function.

Here is an example for ResNet50.

I have installed onnx 1.7.0,and run ResNet50,the output is like this: Ran 8 tests in 0.004s OK (skipped=8) Skipped: Tensorflow 2.x only tests Skipped: Tensorflow 2.x only tests Skipped: Tensorflow 2.x only tests Skipped: Tensorflow 2.x only tests Skipped: Tensorflow 2.x only tests Skipped: Tensorflow 2.x only tests Skipped: Tensorflow 2.x only tests Skipped: Tensorflow 2.x only tests

so this output can prove keras2onnx itself is normal, parse onnxmodel transfored using tensorrt but get network.layer=0 is another ploblem?

zlpson avatar Dec 29 '20 03:12 zlpson

This is probably because you are using old onnx package. Try onnx==1.7.0. You can also set target_opset=12 in convert_keras function.

Here is an example for ResNet50.

use keras2onnx.convert_keras function to transfer model,the output is: The ONNX operator number change on the optimization: 450 -> 122 I1229 11:51:59.263113 10340 topology.py:348] The ONNX operator number change on the optimization: 450 -> 122

zlpson avatar Dec 29 '20 03:12 zlpson

From the log, the onnx model looks good. Do you transfer to tensorrt through https://github.com/onnx/onnx-tensorrt ? If so, you can raise an issue there.

jiafatom avatar Dec 29 '20 04:12 jiafatom

From the log, the onnx model looks good. Do you transfer to tensorrt through https://github.com/onnx/onnx-tensorrt ? If so, you can raise an issue there.

ok,I will try to raise an issue there.But I want to ensure that the onnx model is correct.By the way,I use netron to see the onnx model,there will be a transpose layer which is not in model.Dose onnx only support channel_first?when the model is channle_last,is it transposed to the channel_first shape by automatically adding transposed layer?

zlpson avatar Dec 29 '20 06:12 zlpson

Yes, it adds Transpose layer as you said.

jiafatom avatar Dec 29 '20 06:12 jiafatom

Yes, it adds Transpose layer as you said.

Will it affect the parse process using tensorrt?The worst situation,I mean,lead to parsing failed?

zlpson avatar Dec 29 '20 07:12 zlpson

No, the parse process should put no assumption on the onnx model.

jiafatom avatar Dec 29 '20 16:12 jiafatom