Adding custom Create ML model into Create ML Components pipeline

I have been reading up on the new Create ML Components documentation, mostly the sample code for 'Counting Human Counting human body action repetitions in a live video feed', which can be found here.

I currently have a body action classifier model built with UIKit/SwiftUI front-end and a relatively complex back-end, but this solution looks far more clean and is 100% SwiftUI - which is a big plus for me.

Based on this sample code and documentation, how would I use my own body action classifier with this sample code? Purely interested and amazed by how lightweight it is and would love to see how a CreateML model could be implemented here.

Answered by in 747238022

Hey Doug,

You might try something like:

let model = try MLModel(contentsOf: **your model url**)
let adaptor = try MLModelClassifierAdaptor<Double>(model: model)
let array = MLShapedArray<Double>(**your MLMultiArray**) (see [documentation](https://developer.apple.com/documentation/coreml/mlshapedarray), similar to MLMultiArray).
let results = try await adaptor(array)

Your best option is to have your custom classifier as a Core ML model (.mlmodel). Then you can use MLModelClassifierAdaptor to add it to your components pipeline.

Thank you for the response! Currently the model is being passed a MLMultiArray, and the is being passed for the MLModelClassifierAdaptor. I am relatively new to the CoreML framework - would you have example code on how to add an action body pose model into a Create ML Component pipeline? So far I have only found the Counter example. Many thanks in advance!

Accepted Answer

Hey Doug,

You might try something like:

let model = try MLModel(contentsOf: **your model url**)
let adaptor = try MLModelClassifierAdaptor<Double>(model: model)
let array = MLShapedArray<Double>(**your MLMultiArray**) (see [documentation](https://developer.apple.com/documentation/coreml/mlshapedarray), similar to MLMultiArray).
let results = try await adaptor(array)
Adding custom Create ML model into Create ML Components pipeline
 
 
Q