CoreML Error when converting from sklearn RandomForestClassifier

I am learning some deep learning with images by following this tutorial:


https://blog.hyperiondev.com/index.php/2017/12/11/machine-learning/


The training part went pretty successfully, I even made my own set of data that worked with the training code.


Now I want to use the trained data in one of my iOS app (I am using my own data but the format is identical to the one provided).


Here is the code from coremltools section:


# convert to Apple CoreML
input_name = "shape"
output_features = ("resultsprob", "result")
models = coremltools.converters.sklearn.convert(clf, input_name, output_features)
models.save("shapes.mlmodel")


The error happened on line #4:

ValueError: Class labels must be all of type int or all of type string.


Any ideas on how I can fix this?

Replies

Hi, I'm running to the same problem. input_features and output_feature_names are all strings and yet this error keeps showing.

Any help?

I had the same problem. The input_name and output_features were both Strings, but the actual problem was the type associated with values of output_features. Check if they are Int or String.

I had the same problem because my type of output feature was unsigned int (uint8) changed that to signed int this fixed the problem

Hi there,


Don't suppose you could help me out on how exactly I change the output feature type on an sklearn model? I've trained a multiclass LinearSVC, which outputs a numpy array of float64 values. Getting this error message and I'm not sure how to fix it.

Figured it out. For any future people who may be interested, I was training my model with floats as target class labels. I had to completely retrain the model, converting the target class labels from floats to ints in Python (floats to string would have also worked). For some reason CoreML cannot use floats as target output values.

Thank you! This really works!