Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KeyError: key "conv2d_9_2/kernel:0" not found #34

Open
WenJieWan opened this issue Jan 13, 2020 · 2 comments
Open

KeyError: key "conv2d_9_2/kernel:0" not found #34

WenJieWan opened this issue Jan 13, 2020 · 2 comments

Comments

@WenJieWan
Copy link

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")

@RKowalsky
Copy link

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?

@andevellicus
Copy link

andevellicus commented Jun 17, 2020

Similar issue. I have TF 2.1, ran keras2onnx on my model, and then tried to load into Julia. Got conv3d_0/kernal:0 not found.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants