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

AssertionError: batch_normalization_1/keras_learning_phase:0 is disconnected

Open monteksingh opened this issue 5 years ago • 6 comments

I trained an Efficientnet B2 model using [https://pypi.org/project/efficientnet/]

I am using tensorflow==1.14.0 numpy==1.17.0 onnx==1.7.0 Keras==2.2.4 efficientnet==0.0.4

During the conversion, I get multiple warnings

WARN: No corresponding ONNX op matches the tf.op node swish_69/swish_f32 of type swish_f32
The generated ONNX model needs run with the custom op supports.

WARNING: Logging before flag parsing goes to stderr.

W0731 16:03:10.044219 139835338614528 parser.py:303] WARN: No corresponding ONNX op matches the tf.op node swish_69/swish_f32 of type swish_f32
The generated ONNX model needs run with the custom op supports.
WARN: No corresponding ONNX op matches the tf.op node drop_connect_16/cond/Merge of type Merge
The generated ONNX model needs run with the custom op supports.

W0731 16:03:10.045672 139835338614528 parser.py:303] WARN: No corresponding ONNX op matches the tf.op node drop_connect_16/cond/Merge of type Merge                 
The generated ONNX model needs run with the custom op supports.
WARN: No corresponding ONNX op matches the tf.op node drop_connect_16/cond/Switch_1 of type Switch
The generated ONNX model needs run with the custom op supports.

W0731 16:03:10.045809 139835338614528 parser.py:303] WARN: No corresponding ONNX op matches the tf.op node drop_connect_16/cond/Switch_1 of type Switch
The generated ONNX model needs run with the custom op supports.
WARN: No corresponding ONNX op matches the tf.op node drop_connect_16/cond/Shape/Switch of type Switch

The generated ONNX model needs run with the custom op supports.
W0731 16:03:10.045921 139835338614528 parser.py:303] WARN: No corresponding ONNX op matches the tf.op node drop_connect_16/cond/Shape/Switch of type Switch
The generated ONNX model needs run with the custom op supports.

And the conversion fails with the following error. AssertionError: batch_normalization_1/keras_learning_phase:0 is disconnected, check the parsing log for more details.

monteksingh avatar Jul 31 '20 18:07 monteksingh

The example for efficientNet conversion can be found in our nightly build here. It needs tensorflow >= 2.1.0 and set keras.backend.set_learning_phase(0).

jiafatom avatar Jul 31 '20 21:07 jiafatom

I tried to convert the Model using the following dependencies

tensorflow_gpu = 2.3.0 keras=2.4.3 efficientnet= 0.0.4

Code

import keras2onnx
from keras.models import Model, load_model
import efficientnet
model = load_model(model_path, compile=False)
# converting to ONNX
onnx_model = keras2onnx.convert_keras(model, name=model.name)
keras2onnx.save_model(onnx_model, onnx_model_path)

After doing so I get

WARN: No corresponding ONNX op matches the tf.op node model_2/swish_69/IdentityN of type IdentityN The generated ONNX model needs run with the custom op supports. The ONNX operator number change on the optimization: 982 -> 601

Pls help me understand how can I resolve this issue.

monteksingh avatar Aug 03 '20 20:08 monteksingh

tensorflow 2.3.0 support is ongoing, please use tf 2.2 at this moment. This IdentityN is recently supported, so please pull keras2onnx from master source code rather than pypi.

jiafatom avatar Aug 03 '20 20:08 jiafatom

See my previous answer, you need pull keras2onnx from master source code: pip install -U git+https://github.com/onnx/keras-onnx

jiafatom avatar Aug 03 '20 22:08 jiafatom

Thanks for your help.

I followed all the steps and the conversion was successful.

But the issue now is, I wanted to import this model to Snap Lens Studio. But when I import the ONNX model, I get this error 'Transpose' layer type is not supported I know this issue is not related to this repo. But if anyone is facing the same issue, as I am. Pls help....

monteksingh avatar Aug 03 '20 22:08 monteksingh

Should we still use TF 2.2 for this?

Also here: https://github.com/onnx/keras-onnx/blob/master/applications/nightly_build/test_efn.py#L27

is this the standard efficientnet from tf.keras?

my error is the following: AssertionError: functional_3/efficientnetb6/block7c_se_reduce/BiasAdd:0 is disconnected, check the parsing log for more details.

I'm using concat of BERT model & ENet.

ch-hristov avatar Feb 04 '21 12:02 ch-hristov