OnlyFunc

How to train CoreML model using Create ML

There are two main ways to implement AI features for iOS and Mac apps: running computations in the cloud via an API call or locally on the device. As Apple devices continue to become more powerful each year, running machine learning models locally becomes increasingly feasible and efficient. CoreML is the framework you need.

CoreML is Apple's machine learning framework that enables the running of machine learning models locally on iOS, macOS, watchOS, and tvOS. It's designed to be easy to use and integrate into your app. It’s built to take full advantage of Apple’s processors (such as the A-series chips and Neural Engine) for lightning-fast performance.

You can take ready-made CoreML model from Apple or if you need specific use-case for your app, you can train a new model for yourself using Create ML app. In this post, I'll share how to train CoreML model .

How to train CoreML Model

Apple ship Create ML app with Xcode to allow you train your own CoreML model. You can open it by going to Xcode menu → Open Developer Tool → Create ML.

Click on New Document to create a new training.

image

For this post, we'll train an object detection model that will detect a hand palm and drawing a bounding box on top of it.

Datasets preparation

In general, there's few tips on preparing dataset for CoreML

We'll use this dataset from Roboflow that's already anotated and ready to download in Create ML JSON Format.

Once downloaded, we'll start training with Create ML.

Training an object detection model

After choosing Object Detection training, tap Next, give your model name, author, license and description. Finally, save the Create ML documents.

Next is we'll put the training, validation and testing data on the appropriate section.

image

Under the Data section, there's Parameters that you can tweak and adjust as you need. I usually use default value and rarely change this.

Here's some brief explanation of each options:

Once done, we can start training by click on Train button.

Testing the model

Once training is finished, you can try the model inside of Create ML apps by going to the Preview tab. You can drag and image to the sidebar and see the result on the right where it draws bounding box of palm images.

image

You can also see the model details in Output tab. For this model, you need an image as an input. You can also specify iouThreshold and confidenceThreshold parameter when running predictions.

image

With Create ML, the process of training machine learning models is made accessible even to those with minimal machine learning expertise. By simply providing a well-prepared dataset, adjusting a few parameters, and initiating the training process, you can develop a model tailored to your needs.

On the next post, I'll share how to use this models on iOS app. So, stay tune!

#CoreML #Machine Learning #Xcode