Thijs van der Heijden
Thijs van der Heijden

Reputation: 1176

Keras Convolutional Neural Network converted to CoreMLModel has an input of multiarray instead of image?

# 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'])

This is the code I wrote for my Keras Convolutional neural network, and in keras when training with keras 2.0.6 and tensorflow 1.1.0 it gets a great accuracy of 86% on the test set. When I export this model to an CoreML model, the input is not an image, but a multiarray? How do I fix this as the input of the network is actually a 64x64 image with colors?

Upvotes: 1

Views: 124

Answers (1)

Matthijs Hollemans
Matthijs Hollemans

Reputation: 7892

In your coremltools conversion script, specify the input_image_names="input" parameter.

Upvotes: 2

Related Questions