转换为CoreMLModel的Keras卷积神经网络具有多阵列输入而不是图像?

时间:2017-11-04 14:19:06

标签: python deep-learning keras coreml

# Importing the Keras libraries and packages
from keras.models import Sequential
from keras.layers import Conv2D
from keras.layers import MaxPooling2D
from keras.layers import Flatten
from keras.layers import Dense
from keras.layers import Dropout

# Initialising the CNN
chars74k_classifier = Sequential()

# Adding the first convolutional layer
chars74k_classifier.add(Conv2D(32, (3, 3), activation = 'relu', input_shape = (64, 64, 3)))

# Adding the max pooling layer
chars74k_classifier.add(MaxPooling2D(pool_size = (2, 2)))

chars74k_classifier.add(Dropout(0.25))

# Adding the second convolutional layer
chars74k_classifier.add(Conv2D(32, (3, 3), activation='relu'))

# Adding a second max pooling layer
chars74k_classifier.add(MaxPooling2D(pool_size = (2, 2)))

# Adding the third convolutional layer
chars74k_classifier.add(Conv2D(64, (3, 3), activation='relu'))

# Adding a third max pooling layer
chars74k_classifier.add(MaxPooling2D(pool_size = (2, 2)))

chars74k_classifier.add(Dropout(0.50))

# Adding the fourth convolutional layer
chars74k_classifier.add(Conv2D(128, (3, 3), activation='relu'))

# Adding a fourth max pooling layer
chars74k_classifier.add(MaxPooling2D(pool_size = (2, 2)))

# Adding the flattening layer
chars74k_classifier.add(Flatten())

# Adding the fully connected layers (Normal ANN)
chars74k_classifier.add(Dense(activation = 'relu', units = 128))
chars74k_classifier.add(Dense(activation = 'relu', units = 128))
chars74k_classifier.add(Dense(activation = 'softmax', units = 26))

# Compiling the CNN
chars74k_classifier.compile(optimizer='Adadelta',
              loss='categorical_crossentropy',
              metrics=['accuracy'])

这是我为Keras Convolutional神经网络编写的代码,在使用keras 2.0.6和tensorflow 1.1.0进行训练时,它在测试集上获得了86%的高精度。当我将此模型导出到CoreML模型时,输入不是图像,而是多阵列?我如何解决这个问题,因为网络的输入实际上是带有颜色的64x64图像?

1 个答案:

答案 0 :(得分:2)

在coremltools转换脚本中,指定input_image_names="input"参数。