Integrating selfmade CoreML Model in swift UI project

Hello,

i have been working on a iOS swift UI project and want to integrate my own ML Model (generated with create ML) into the app. My create ML Model is a tabular-Regressor Model wich works fine in the create ML Preview. I was following this guide:

https://developer.apple.com/documentation/coreml/integrating_a_core_ml_model_into_your_app

i have tried to integrate the model into the app (Xcode 13.4.1). I load the file into the project navigator. When i try to create the model in the code with

let model = MyModelName()

i get the error:

Cannot find 'MyModelName' in scope

There is also an error message when i try to build:
Command CoreMLModelCodegen failed with a nonzero exit code

Other Models (like the ones downloadable from apple) seem to get recognized.
To me it looks like the automatic code for my model could not be created for some reason.

I would greatly appreciated any ideas.

Thank You

@rob42

Hi Robert,

Welcome to the community.

The first thing that comes to mind is whether Xcode is aware that the model exists.

When you added your own mlmodel file to the project did you ensure that the target membership option was checked when the dialog box was presented at the point that you dragged the file in?

To check that the target membership is set you should select the file, look to the right hand panel and in the File Inspector panel ensure that there is a checkmark in Target Membership.

Hi Chris,

thanks for your reply! Target Membership is checked. I assume it has to do something with my model.

Robert

@rob42

It could be the model.

I’m wondering if this tutorial from Paul Hudson might help you or give you a few pointers with training a model with data that you have.

https://www.hackingwithswift.com/books/ios-swiftui/connecting-swiftui-to-core-ml

I will check that out! Thanks!

I narrowed it down.
It turns out the problem was in the trainingsdata (especially the title row): it contained some umlauts (ä, ü etc.)
While createML was fine with that, Xcode was not. Removing them solved the problem. The model is now recognized in Xcode.

Well done.