I created an activity classifier model using CreateML and imported the model into my XCode project. And am trying to find answers to the following questions.. I created the instance of the model like this:
let activityClassifier = MyActivityClassifier_4()
- How am I supposed to access the constants of the model? For example, the prediction window value that shows here on the metadata of the model. I am having hard time finding an example code to get these values. I tried something along these line
let predictionWindowSize = activityClassifier.model.modelParametersbut could not figure it out.
- Also, the model expects
stateInas an input. How can I create an empty MLMultiArray that matches the expected shape?stateIn: MLMultiArray(shape: <#T##[NSNumber]#>, dataType: <#T##MLMultiArrayDataType#>)I assume there is a suggested way to fetch features shape and etc...
I would greatly appreciate if you could also direct me on how to find these answers...
You can get the metadata by accessing
modelDescription.metadata. For author, description, license, and version, you can use the appropriateMLModelMetadataKey:e.g.
For the metadata in the "additional metadata" section, you need to use the
.creatorDefinedKeykey to get a nested dictionary. Things likeprediction_windowsare stored there.For the inputs, you can see the shape and type of the array just by going to the "Predictions" tab after opening your model in Xcode.
In this case, both of the inputs shown above would be a double array with a single dimension, 100 elements in length. You can create it like this.
If you want to do this programmatically, you can too. Just give the name of your input to
model.modelDescription.inputDescriptionsByName, and get themultiArrayConstraint.