2 Replies
      Latest reply: Aug 30, 2017 4:29 PM by tettoffensive RSS
      joe@uber Level 1 Level 1 (0 points)

        When importing a keras model, the kerasconverter assumes that images are imported as <width, height, color space>.  I would like to have a paramter to either configure `image_input_names` or a flag to have `image_input_names` prase inputs as <width, color space, height>



        ValueError                                Traceback (most recent call last)
        /home/keras/test/train.py in <module>()
             49 print model.input_shape
        ---> 51 coremlmodel = coremltools.converters.keras.convert(model, class_labels="labels.txt", image_input_names="input1")
        /opt/conda/envs/coreml/lib/python2.7/site-packages/coremltools/converters/keras/_keras_converter.pyc in convert(model, input_names, output_names, image_input_names, is_bgr, red_bias, green_bias, blue_bias, gray_bias, image_scale, class_labels, predicted_feature_name)
            429                                           blue_bias = blue_bias,
            430                                           gray_bias = gray_bias,
        --> 431                                           image_scale = image_scale)
            433     # Return the protobuf spec
        /opt/conda/envs/coreml/lib/python2.7/site-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)
           1670                             input_.type.imageType.colorSpace = _FeatureTypes_pb2.ImageFeatureType.ColorSpace.Value('RGB')
           1671                     else:
        -> 1672                         raise ValueError("Channel Value %d not supported for image inputs" % channels)
           1673                     input_.type.imageType.width = width
           1674                     input_.type.imageType.height = height
        ValueError: Channel Value 100 not supported for image inputs


        Here is a link to samle code on GitHub:  https://github.com/joeblau/coremltools-demo

        • Re: ValueError: Channel Value %d not supported for image inputs
          allenlin Apple Staff Apple Staff (20 points)

          Thanks for trying out CoreML Beta and sharing your feedback! Keras supports two ways of passing image inputs:

          <height, width, color space>, and <color space, height, width>. The Keras conversion tool in CoreML Beta supports only <height, width, color space>. The CoreML team is working on supporting <height, width, color space> configuration. Stay tuned for updates.


          The <width, color space, height> is not the most common configuration of image data layout. One suggestion for you would be to transpose the image input. If that's not something you want to change, you can also try adding a permute layer as the first layer to the Keras model:

          width, color_space, height = 100, 3, 100
          # choose this for <height, width, color space>
          model.add(Permute((3,1,2)), input_shape=(width, color_space, height))
          # choose this for <color space, height, width>
          model.add(Permute((2,3,1)), input_shape=(width, color_space, height))
          # Add the rest of the layers
          model.add(Convolution2D(32, 3, 3,border_mode='same'))
          # ...


          Unfortunately, with this work around, you would not be able to pass in an image to the model, you would instead need to use the MLMultiArray as input type:

          coremlmodel = coremltools.converters.keras.convert(model,
                                                             class_labels = 'label.txt')