Here's a quick setup guide for using custom Core ML models in iOS projects.
- A Core ML model file called Digits.mlmodel that recognizes the numbers 0-9 in an image.
- You have dragged this model into Xcode and can access the model
let model = Digits()in your code.
- Your Fritz API key is
- Your Fritz AI model ID for the Digits model is
1. Conform Your Model
In order to expose Fritz AI functionality to your Xcode generated
Digits class, you must conform that class to a Fritz protocol that tells the SDK the about your API key and model id for that model.
Create a new file called :code:
Digits+Fritz.swift and conform your class like so:
2. Update Model Usage
By conforming the Digits class to the protocol we have exposed a :code:
.fritz() function which injects an instrumented MLModel into the instance of that class.
And change them to:
All of your
prediction calls stay the same and they will be instrumented by the SDK.
3. Build and run your app
Test out each part of your app that uses the prediction, then look at the Fritz AI dashboard to see if data is showing up.
You do not have to bundle the
mlmodel in your app package. You can download the model after a user installs your app. You may want to do this if you are trying to shrink the size of your initial app download.
Be aware of UX difficulties this may create. You will be unable to run any predictions until the download completes.
Here is an example of how to download the
Digits model created above.
First you must generate and include the
Digits.swift class file:
Then, add that generated file to your app: