Create Image Classifier with CreateML


Introductions

In WWDC 2018 event, Apple has introduced their brand new Machine Learning Framework call CreateML. It allow you to build machine learning model very quick and easy by using Xcode and Swift. It's designed for simplicity and performance. It was build based upon the Metal to run our training process on the GPU rather than CPU, so that we can train image classifier for 20000 images within an hour according to Apple.

Basic System Requirements

  • Beta of Xcode 10
  • MacOS 10.14 (Mojave)

Preparing the dataset

In this article, I will create an Image Classifier to classify between boy and girl. So let's go ahead and download images for boys and girls from Google and place it in two different folder as it's going to be the label of our Image Classifier.

Data Traning

After get all the dataset, let's go ahead and create new Playground in Xcode for macOS.

Let's go ahead and write some code.
I separate all of those dataset into two parts, 80% TraningData and 20% for TestingData.

import CreateMLUI

let builder = MLImageClassifierBuilder()
builder.showInLiveView()

then run this code. after that you should see something as shown in the picture below:

after that drag and drop your TraningData dataset into the ImageClassifier in Xcode. It took me a fews second to finish training the classifier. After that drag the TestingData dataset into the ImageClassifier for testing our model.

Here we got 100% Training and 100% Evaluation. That's mean our model is ready.
** Note: The more image you give for training, the more accurate image classifier you will get.
You can also export your model as .mlmodel file.

You can use this model in your application with the help of CoreML library.