0

I have been trying to create an IOS App using coreML, I have trained a convolutional neural network in Keras, when I use CoreMLTools to transform this model to a CoreML model it shows that the output is a multidimensional array, but I want it to be a class probability. How do I generate a .txt file with the class labels in Keras?

This is the code I use to generate a coreML model:

import coremltools

coreml_model = coremltools.converters.keras.convert(
                                                    "chars74kV3.0.h5", class_labels = "class_labels.txt", image_input_names= ['input'], input_names=['input'], image_scale=255.)
coreml_model.author = 'Thijs van der Heijden'
coreml_model.license = 'MIT'
coreml_model.description = 'A basic Deep Convolutional Neural Network to classify handwritten letters.'
coreml_model.input_description['input'] = 'A 64x64 pixel Image'
coreml_model.save('chars74k.mlmodel')
Andy Jazz
  • 49,178
  • 17
  • 136
  • 220
Thijs van der Heijden
  • 1,147
  • 1
  • 10
  • 25

1 Answers1

1

The class_labels.txt file should just be a plain text file with one label per line, in order of the classes in your training set. For example,

dog
cat
person

would be your label file for a three-class network where class 0 was "dog", class 1 was "cat", and class 2 was "person". If this is a public classification dataset, you should have that information with the dataset, and if it's your own you'll just have to create such a mapping file. You'd have to do this anyway to associate class numbers with values.

Brad Larson
  • 170,088
  • 45
  • 397
  • 571