最近更新到 tensorflow 2.0 并且无法将我的 .h5 模型转换为 .onnx 。曾经是一个非常简单的程序,但现在我遇到了问题。当我运行以下代码时:
# onnx testing
import onnx
import keras2onnx
import os
import tensorflow as tf
from tensorflow.keras.models import load_model
folder = r'\\rdnas'
os.chdir(folder)
#os.environ["TF_KERAS"]='1'
model_loc = folder+'\\model.h5'
model = tf.keras.models.load_model(model_loc)
model.summary()
# Onnx covnersion
onnx_model = keras2onnx.convert_keras(model)
temp_model_file = 'model.onnx'
onnx.save_model(onnx_model, temp_model_file)
Run Code Online (Sandbox Code Playgroud)
当我运行代码时,出现以下错误
Using TensorFlow backend.
Can't import tf2onnx module, so the conversion on a model with any custom/lambda layer will fail!
Model: "sequential_1"
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
DVA_input (Dense) …Run Code Online (Sandbox Code Playgroud)