Search code examples
swiftmachine-learningcoreml

Prepping to update a Core ML Model


Core ML 3 now gives us the ability to perform on-device training. After creating an updatable Core ML Model, we need to perform some function to update it on-device by using the MLUpdateTask function which requires 3 parameters: Model URL, MLBatchProvider and MLModelConfiguration.

Since Core ML 3 was just released, documentation for it is very limited; specifically on how to prepare the training data or an MLBatchProvider

Question: How do you prepare training data or create an MLBatchprovider.


Solution

  • If your Model is Named TestModel a TestModelTrainingInput class should be available.

    let singleTrainingData = try TestModelTrainingInput(input: .init[1,2,3], output_true: .init([4,5,6]))
    let trainingData = MLArrayBatchProvider(array: [singleTrainingData])