简体   繁体   中英

Incorrect input shape in coreml after converting keras model

I have keras model like that:

inputlayer = Input(shape=(126,12))

model = BatchNormalization()(inputlayer)
model = Conv1D(16, 25, activation='relu')(model)
model = Flatten()(model)
model = Dense(output_size, activation='sigmoid')(model)

model = Model(inputs=inputlayer, outputs=model)

Which I convert to coreml :

coreml_model = coremltools.converters.keras.convert(model,
                                                    class_labels=classes)
coreml_model.save('speech_model.mlmodel')

So, I expect to see MultiArray (Double 126x12) , but I see MultiArray (Double 12)

在此处输入图片说明

Could you help to say what I'm doing wrong?

As identified by G-mel It appears that this bug happens because the input is length 2. CoreMLtools then assumes your input has shape [Seq, D] . You can get around this buy adding a reshape layer:

inputlayer = Input(shape=(126 * 12,))

model = Reshape((126,12))(inputlayer)
model = BatchNormalization()(model)
model = Conv1D(16, 25, activation='relu')(model)
model = Flatten()(model)
model = Dense(output_size, activation='sigmoid')(model)

model = Model(inputs=inputlayer, outputs=model)

Your app then has to flatten the input. This is not ideal however because it is not very efficient on the GPU. Hopefully the problem will soon be fixed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM