简体   繁体   English

转换keras模型后,coreml中的输入形状不正确

[英]Incorrect input shape in coreml after converting keras model

I have keras model like that: 我有这样的keras模型:

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

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) 所以,我希望看到MultiArray (Double 126x12) ,但是我看到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] . 正如G-mel标识的那样 ,似乎发生此错误是因为输入的长度为2。然后,CoreMLtools假定您的输入具有[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. 但是,这并不理想,因为在GPU上效率不是很高。 Hopefully the problem will soon be fixed. 希望这个问题将很快得到解决。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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