Reputation: 2818
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
.
Upvotes: 0
Views: 757
Reputation: 1686
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])
Upvotes: 1
Reputation: 7892
To provide data to Core ML, you create an MLFeatureProvider
object. This returns one or more MLFeatureValue
objects, one for each input in your model. Normally the auto-generated class does this behind the scenes.
If you want to work with a batch, you create an MLBatchProvider
that has multiple MLFeatureProviders
, one for each example.
Making an MLBatchProvider
for predictions isn't so hard: just put your MLFeatureProviders
in an array and then use MLArrayBatchProvider
. Again, the auto-generated class has a helper method for this.
For training you probably want to load the data on-the-fly, do random augmentations, and so on. In that case, you'll want to make a new class that adopts the MLBatchProvider
protocol. It should return an MLFeatureProvider
for each example. This time the MLFeatureProvider
does not just have the MLFeatureValue
for the example but also an MLFeatureValue
for the target / true label. (The auto-generated class has a helper class for this training feature provider, but not for the training batch provider.)
I haven't actually gotten any of the new training APIs to work yet (they crash on beta 2), so I'm not 100% sure yet how the MLBatchProvider
would cycle through an entire epoch of training examples.
Upvotes: 0