onnx / keras-onnx

Convert tf.keras/Keras models to ONNX
Apache License 2.0
381 stars 109 forks source link

There is an error(<class 'AttributeError'>) happened during optimizing on the converted model! #309

Open ducmanhnguyen opened 4 years ago

ducmanhnguyen commented 4 years ago

I'm trying to convert keras model from https://github.com/fizyr/keras-retinanet to onnx, and this error show up. Anyone have the same problem in convert keras models to onnx?

Thanks!

Instructions for updating: Usetf.compat.v1.graph_util.tensor_shape_from_node_def_name` node bn3d_branch2c/FusedBatchNorm of type FusedBatchNorm cannot be converted, fall back to tf2onnx node bn4f_branch2c/FusedBatchNorm of type FusedBatchNorm cannot be converted, fall back to tf2onnx node bn5b_branch2c/FusedBatchNorm of type FusedBatchNorm cannot be converted, fall back to tf2onnx node bn5c_branch2b/FusedBatchNorm of type FusedBatchNorm cannot be converted, fall back to tf2onnx node bn3c_branch2c/FusedBatchNorm of type FusedBatchNorm cannot be converted, fall back to tf2onnx node bn4e_branch2c/FusedBatchNorm of type FusedBatchNorm cannot be converted, fall back to tf2onnx node bn5a_branch2c/FusedBatchNorm of type FusedBatchNorm cannot be converted, fall back to tf2onnx node bn5a_branch1/FusedBatchNorm of type FusedBatchNorm cannot be converted, fall back to tf2onnx node bn3d_branch2b/FusedBatchNorm of type FusedBatchNorm cannot be converted, fall back to tf2onnx node bn4f_branch2b/FusedBatchNorm of type FusedBatchNorm cannot be converted, fall back to tf2onnx node bn5b_branch2b/FusedBatchNorm of type FusedBatchNorm cannot be converted, fall back to tf2onnx node bn3b_branch2c/FusedBatchNorm of type FusedBatchNorm cannot be converted, fall back to tf2onnx node bn4d_branch2c/FusedBatchNorm of type FusedBatchNorm cannot be converted, fall back to tf2onnx node bn3c_branch2b/FusedBatchNorm of type FusedBatchNorm cannot be converted, fall back to tf2onnx node bn4e_branch2b/FusedBatchNorm of type FusedBatchNorm cannot be converted, fall back to tf2onnx node bn5c_branch2a/FusedBatchNorm of type FusedBatchNorm cannot be converted, fall back to tf2onnx node bn5a_branch2b/FusedBatchNorm of type FusedBatchNorm cannot be converted, fall back to tf2onnx node bn3a_branch2c/FusedBatchNorm of type FusedBatchNorm cannot be converted, fall back to tf2onnx node bn3a_branch1/FusedBatchNorm of type FusedBatchNorm cannot be converted, fall back to tf2onnx node bn4c_branch2c/FusedBatchNorm of type FusedBatchNorm cannot be converted, fall back to tf2onnx node bn3d_branch2a/FusedBatchNorm of type FusedBatchNorm cannot be converted, fall back to tf2onnx node bn3b_branch2b/FusedBatchNorm of type FusedBatchNorm cannot be converted, fall back to tf2onnx node bn4f_branch2a/FusedBatchNorm of type FusedBatchNorm cannot be converted, fall back to tf2onnx node bn4d_branch2b/FusedBatchNorm of type FusedBatchNorm cannot be converted, fall back to tf2onnx node bn5b_branch2a/FusedBatchNorm of type FusedBatchNorm cannot be converted, fall back to tf2onnx node bn4b_branch2c/FusedBatchNorm of type FusedBatchNorm cannot be converted, fall back to tf2onnx node bn3c_branch2a/FusedBatchNorm of type FusedBatchNorm cannot be converted, fall back to tf2onnx node bn3a_branch2b/FusedBatchNorm of type FusedBatchNorm cannot be converted, fall back to tf2onnx node bn4e_branch2a/FusedBatchNorm of type FusedBatchNorm cannot be converted, fall back to tf2onnx node bn4c_branch2b/FusedBatchNorm of type FusedBatchNorm cannot be converted, fall back to tf2onnx node bn5a_branch2a/FusedBatchNorm of type FusedBatchNorm cannot be converted, fall back to tf2onnx node bn2c_branch2c/FusedBatchNorm of type FusedBatchNorm cannot be converted, fall back to tf2onnx node bn4a_branch2c/FusedBatchNorm of type FusedBatchNorm cannot be converted, fall back to tf2onnx node bn4a_branch1/FusedBatchNorm of type FusedBatchNorm cannot be converted, fall back to tf2onnx node bn3b_branch2a/FusedBatchNorm of type FusedBatchNorm cannot be converted, fall back to tf2onnx node bn4d_branch2a/FusedBatchNorm of type FusedBatchNorm cannot be converted, fall back to tf2onnx node bn4b_branch2b/FusedBatchNorm of type FusedBatchNorm cannot be converted, fall back to tf2onnx node bn2b_branch2c/FusedBatchNorm of type FusedBatchNorm cannot be converted, fall back to tf2onnx node bn3a_branch2a/FusedBatchNorm of type FusedBatchNorm cannot be converted, fall back to tf2onnx node bn2c_branch2b/FusedBatchNorm of type FusedBatchNorm cannot be converted, fall back to tf2onnx node bn4c_branch2a/FusedBatchNorm of type FusedBatchNorm cannot be converted, fall back to tf2onnx node bn4a_branch2b/FusedBatchNorm of type FusedBatchNorm cannot be converted, fall back to tf2onnx node bn2a_branch2c/FusedBatchNorm of type FusedBatchNorm cannot be converted, fall back to tf2onnx node bn2a_branch1/FusedBatchNorm of type FusedBatchNorm cannot be converted, fall back to tf2onnx node bn2b_branch2b/FusedBatchNorm of type FusedBatchNorm cannot be converted, fall back to tf2onnx node bn4b_branch2a/FusedBatchNorm of type FusedBatchNorm cannot be converted, fall back to tf2onnx node bn2c_branch2a/FusedBatchNorm of type FusedBatchNorm cannot be converted, fall back to tf2onnx node bn2a_branch2b/FusedBatchNorm of type FusedBatchNorm cannot be converted, fall back to tf2onnx node bn4a_branch2a/FusedBatchNorm of type FusedBatchNorm cannot be converted, fall back to tf2onnx node bn_conv1/FusedBatchNorm of type FusedBatchNorm cannot be converted, fall back to tf2onnx node bn2b_branch2a/FusedBatchNorm of type FusedBatchNorm cannot be converted, fall back to tf2onnx node bn2a_branch2a/FusedBatchNorm of type FusedBatchNorm cannot be converted, fall back to tf2onnx WARNING:tensorflow:From /root/venv/keras-onnx/lib/python3.6/site-packages/keras2onnx/_builtin.py:59: The name tf.Session is deprecated. Please use tf.compat.v1.Session instead.

There is an error(<class 'AttributeError'>) happened during optimizing on the converted model!`

jiafatom commented 4 years ago

Which version of keras2onnx you use? Can you pull the latest master and try?

ducmanhnguyen commented 4 years ago

Which version of keras2onnx you use? Can you pull the latest master and try?

I used the latest master of keras2onnx, and the problem come out

jiafatom commented 4 years ago

Which version of tensorflow? Can you specify the pretrained model so that we can debug?

wenbingl commented 4 years ago

Which version of keras2onnx you use? Can you pull the latest master and try?

I used the latest master of keras2onnx, and the problem come out

In that case, you need manually pip install git+https://github.com/microsoft/onnxconverter-common.git

ducmanhnguyen commented 4 years ago

Which version of tensorflow? Can you specify the pretrained model so that we can debug?

keras2onnx: latest version tensorflow (I tried both cpu and gpu version): 1.14.0 keras: latest version

keras model I download from here: https://github.com/fizyr/keras-retinanet/releases/download/0.5.1/resnet50_coco_best_v2.1.0.h5

thanks!

ducmanhnguyen commented 4 years ago

Which version of tensorflow? Can you specify the pretrained model so that we can debug?

even I run the script from example in readme, same problem occur! (keras2onnx latest, tensorflow cpu 1.14.0, keras latest)

import keras2onnx from keras.applications.resnet50 import ResNet50 model = ResNet50(include_top=True, weights='imagenet') onnx_model = keras2onnx.convert_keras(model, model.name)

jiafatom commented 4 years ago

Resnet50 is in our nightly build and it works, see test_ResNet50 in test_keras_applications.py you need manually pip install git+https://github.com/microsoft/onnxconverter-common.git

jiafatom commented 4 years ago

I just tried retina net and find ValueError: get tensor value: TFNodes/filtered_detections/map/while/PadV2_2/paddings_Concat__14245 must be Const, this error looks different from what you provided here. I will look into it later.

jiayiliu commented 4 years ago

I got the same error, but it seems that the resulting converted model works fine.

jiafatom commented 4 years ago

I got the same error, but it seems that the resulting converted model works fine.

This error is optimization error, we will skip optimization if the error happens, so it works fine. Will take a look later.

ducmanhnguyen commented 4 years ago

I just tried retina net and find ValueError: get tensor value: TFNodes/filtered_detections/map/while/PadV2_2/paddings_Concat__14245 must be Const, this error looks different from what you provided here. I will look into it later.

this problem could be solve by using opset target 10 in convert step. Anyway the error as I stated in the issue title still remain, when I use the onnx runtime to load, it's said the model is bad and can not load

jiafatom commented 4 years ago

With the latest keras2onnx master (I add a convertor of FusedBatchNorm at keras side), I find that the inside tf2onnx converter lead to an invalid graph for TensorArrayGatherV3 conversion. It may take sometime to fix.

Polymorphhh commented 4 years ago

I stumbled upon the same problem (about TensorArrayGatherV3 conversion) and I wonder if there is any news about a fix or a workaround.

I'm using the latest version of keras2onnx and onnxconverter-common (1.6.5).