3 Replies
      Latest reply: Aug 22, 2017 1:57 PM by tettoffensive RSS
      Flowinger Level 1 Level 1 (0 points)



        I am trying to convert a keras model into a CoreML model.:

        scale = 1./255
        coreml_model = coremltools.converters.keras.convert(model,


        I get the following error:

        429 blue_bias = blue_bias
        430 gray_bias = gray_bias
        431 image_scale = image_scale)
        433 # Return the protobuf spec /usr/local/lib/python2.7/dist-packages/coremltools/models/neural_network.pyc in set_pre_processing_parameters(self, image_input_names, is_bgr, red_bias, green_bias, blue_bias, gray_bias, image_scale)
        1661 if input_.type.WhichOneof('Type') == 'multiArrayType':
        1662 array_shape = tuple(input_.type.multiArrayType.shape)
        -> 1663 channels, height, width = array_shape 
        1664 if channels == 1: 
        1665 input_.type.imageType.colorSpace = _FeatureTypes_pb2.ImageFeatureType.ColorSpace.Value('GRAYSCALE') 
        ValueError: need more than 1 value to unpack

        I can't manage to get my model into Xcode the right way. It always shows MultiArray as input type instead of Image<RGB,224,224>.

        The shape is right I guess (channel, height, width):

        Neural Network compiler 315: 175 , name = dense_25__activation__, output shape : (C,H,W) = (468, 1, 1)


        Any ideas/suggestions? Thanks in advance!

        • Re: Convert keras model
          kerfuffle Level 2 Level 2 (80 points)

          Note that in Keras the data is specified as (height, width, channels) if you're using the TensorFlow back-end. So make sure your Keras model puts its data shapes in that order, not in (channels, height, width).


          [Actually, this depends on the "image_data_format" setting in your ~/keras/keras.json config file.]

          • Re: Convert keras model
            jjiang Level 1 Level 1 (0 points)

            From the error informaiton, it looked like your keras model's input is gray scale image. However you tyied to normalize the input as rgb image so as to cause the error.

            • Re: Convert keras model
              tettoffensive Level 1 Level 1 (0 points)

              Did you ever figure this out?


              The output of my keras model following the tutorial can't be converted into an image because the model looks like this:


              name: "image"
              type {
                   multiArrayType {

                        shape: 3

                        dataType: DOUBLE



              My keras.json:


                  "epsilon": 1e-07,
                  "floatx": "float32",
                  "image_data_format": "channels_last",
                  "backend": "tensorflow"


              I'm using keras 2.0.4, tensorflow 1.1, coremltools 0.5.1, python 2.7


              It seems to me that it is not generating the model correctly