[Core ML] Incorporate an automatically generated ML model into the app

What is this article?

This is the procedure for introducing the unique model trained in Create ML App into the app.

environment

macOS 10.15.7 Xcode 12.1 Swift 5.3

procedure

Train the model

This is done in the Create ML App. I created a model to identify Tomica (minicar toy).

Incorporate into Xcode project

The .mlmodel format model file exported from Create ML App can be incorporated into Xcode by simply dragging and dropping it. At the same time, the code that defines the classes for the ML model is automatically generated.

ML model instance

Some of the code at the time the CoreML framework was announced has been deprecated. You can now create an instance with the following code:

Create an instance of the model


let modelURL = Bundle.main.url(forResource: "MyTomicaClassifier", withExtension: "mlmodelc")!        
let tomicaClassifier = try! VNCoreMLModel(for: MLModel(contentsOf: modelURL))

Recommended Posts

[Core ML] Incorporate an automatically generated ML model into the app
Incorporate circleCI into CircleCI Rails app
Incorporate Elasticsearch into your Rails app
Declare the model as an optional type