I need to convert a .h5
model to a .onnx
, but when I use a BatchNormalization
layer, the code gives the following error:
TypeError: value "" is not valid attribute data type.
And gives the warning:
tf executing eager_mode: True tf.keras model eager_mode: False WARN: No corresponding ONNX op matches the tf.op node keras_learning_phase of type PlaceholderWithDefault The generated ONNX model needs run with the custom op supports.
If I don't use this layer, the code runs and the conversion will succeed, but I need this layer.
The code for conversion is:
from tensorflow.python.keras import backend as K
from tensorflow.python.keras.models import load_model
import onnx
import keras2onnx
onnx_model_name = 'CNN_T_93_96_V_90_88.onnx'
model = load_model('CNN_T_93_96_V_90_88.h5')
onnx_model = keras2onnx.convert_keras(model, model.name)
onnx.save_model(onnx_model, onnx_model_name)
And the line with BatchNormalization
layer is:
model.add(BatchNormalization(momentum=momentum, scale=flag, center=flag))