I'm experiencing the capacity of CoreML for a project. Here's what I managed to do :
- Creating a .pkl file using scikit-learn in Python
- Converting it to a .mlmodel file using coremltools package
- Downloading it to my iOS application
Compile it at run time :
let classifierName = "classifier1" let fileName = NSString(format:"%@.mlmodel",classifierName) let documentsUrl:URL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first as URL! let destinationFileUrl = documentsUrl.appendingPathComponent(fileName as String) let compiledModelUrl = try? MLModel.compileModel(at: destinationFileUrl) let model = try? MLModel(contentsOf: compiledModelUrl!)
Now, I would like to use my model to make prediction. I tried in a sample app to directly embed the .mlmodel file, which allow XCode to create a wrapper class at build time to instantiate input :
let multiArr = try? MLMultiArray.init(shape: [1], dataType: .double)
let input = classifier1Input(input: multiArr!)
let output = try? model.prediction(input: input)
But because I'm downloading the file from server at run time, I do not have access to this kind of wrapper class.
let predict = model?.prediction(from: <MLFeatureProvider>)
Any ideas ?