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

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

Open ducmanhnguyen opened this issue 5 years ago • 13 comments

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: Use tf.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!`

ducmanhnguyen avatar Dec 13 '19 14:12 ducmanhnguyen

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

jiafatom avatar Dec 13 '19 22:12 jiafatom

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

ducmanhnguyen avatar Dec 13 '19 22:12 ducmanhnguyen

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

jiafatom avatar Dec 13 '19 23:12 jiafatom

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

wenbingl avatar Dec 13 '19 23:12 wenbingl

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 avatar Dec 16 '19 07:12 ducmanhnguyen

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)

ducmanhnguyen avatar Dec 16 '19 12:12 ducmanhnguyen

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 avatar Dec 16 '19 18:12 jiafatom

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.

jiafatom avatar Dec 16 '19 18:12 jiafatom

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

jiayiliu avatar Dec 17 '19 17:12 jiayiliu

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.

jiafatom avatar Dec 17 '19 20:12 jiafatom

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

ducmanhnguyen avatar Dec 19 '19 13:12 ducmanhnguyen

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.

jiafatom avatar Dec 27 '19 17:12 jiafatom

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).

Polymorphhh avatar Feb 07 '20 11:02 Polymorphhh