代码之家  ›  专栏  ›  技术社区  ›  Thijs van der Heijden

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

  •  1
  • Thijs van der Heijden  · 技术社区  · 7 年前
    # 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卷积神经网络编写的代码,在Keras中,当使用Keras 2.0.6和tensorflow 1.1.0进行训练时,在测试集上获得了86%的高精度。当我将这个模型导出到CoreML模型时,输入的不是图像,而是多数组?我该如何解决这个问题,因为网络的输入实际上是一个64x64的彩色图像?

    1 回复  |  直到 7 年前
        1
  •  2
  •   Matthijs Hollemans    7 年前

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