从tensorflow.keras优化ONNX模型-错误:内核未定义

时间:2020-05-28 16:30:13

标签: tensorflow tf.keras onnx

尝试优化此简单模型:

from tensorflow import keras
import keras2onnx
from onnx.shape_inference import infer_shapes
from onnx.optimizer import optimize

model = keras.Sequential([
    keras.layers.Conv2D(32, (3, 3), activation='relu', input_shape=(28, 28, 1)),
    keras.layers.GlobalAveragePooling2D(),
    keras.layers.Dense(10)])

model = keras2onnx.convert_keras(model)
model = infer_shapes(model)
model = optimize(model)

导致以下错误:

File ".../lib/python3.7/site-packages/onnx/optimizer.py", line 55, in optimize
    optimized_model_str = C.optimize(model_str, passes)
IndexError: Input conv2d/kernel:0 is undefined!

我正在使用tensorflow = 2.1.0,onnx = 1.7.0和keras2onnx = 1.6.1。

有什么办法解决此问题吗?

0 个答案:

没有答案