You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is was your Keras model created in TensorFlow 1.x or 2.x? We are having a similar issue at our company with reading ONNX files that were written using the keras2onnx package. From the keras2onnx webpage: "keras2onnx has been tested on Python 3.5, 3.6, and 3.7, with TensorFlow 1.x (CI build). It does not support Python 2.x.". Perhaps this matters?
I train a simple cnn model by tensorflow(1.15), and use keras-onnx tool to convert model to onnx.
Next, i load onnx and occur KeyError: key "conv2d_9_2/kernel:0" not found
But, i print the msgs when keras-onnx converts model, and the key "conv2d_9_2/kernel:0" has existed.
The message segments are shown as follows:
ir_version: 6
producer_name: "keras2onnx"
producer_version: "1.6.1"
domain: "onnx"
model_version: 0
doc_string: ""
graph {
node {
input: "conv2d_9_input"
output: "adjusted_input3"
name: "Transpose8"
op_type: "Transpose"
attribute {
name: "perm"
ints: 0
ints: 3
ints: 1
ints: 2
type: INTS
}
doc_string: ""
domain: ""
}
node {
input: "adjusted_input3"
input: "conv2d_9_2/kernel:0"
input: "conv2d_9_2/bias:0"
output: "convolution_output3"
name: "conv2d_9"
op_type: "Conv"
attribute {
name: "auto_pad"
s: "NOTSET"
type: STRING
}
..................................................
..................................................
The model network structure:
mpadding = 'same'
model = Sequential()
model.add(Convolution2D(nb_filters, kernel_size, strides=strides, padding=mpadding, activation='relu', input_shape=input_shape))
model.add(Convolution2D(nb_filters, kernel_size, strides=strides, padding=mpadding, activation='relu'))
model.add(MaxPooling2D(pool_size=pool_size))
model.add(Convolution2D(nb_filters2, kernel_size, strides=strides, padding=mpadding, activation='relu'))
model.add(Convolution2D(nb_filters2, kernel_size, strides=strides, padding=mpadding, activation='relu'))
model.add(MaxPooling2D(pool_size=pool_size))
model.add(Flatten())
model.add(Dense(100, activation='relu'))
model.add(Dropout(0.25))
model.add(Dense(nb_classes, activation='softmax'))
model.compile(optimizer=Adam(lr=0.0001),loss='categorical_crossentropy',metrics=['accuracy'])
model = LSUVinit(model,x_train[:batch_size,:,:,:])
model.fit(x_train, y_train, batch_size=batch_size, epochs=nb_epoch, validation_data=(x_test,y_test), shuffle=True)
model.save('test.h5')
keras2onnx code:
import keras2onnx,onnx
model = load_model('./test.h5')
onnx_model = keras2onnx.convert_keras(model,model.name)
onnx.save_model(onnx_model,"test.onnx")
The text was updated successfully, but these errors were encountered: