Build a Simple ImageClassifier with Kanye & Kim Part1

Apple has released a new thing, CreateML that allows us train a machine learning model to classify images with a couple of lines code.


For setting up the environment, we need Apple Dev account(actually, some people offers a tool for free, but I don’t recommend that because that isn’t from Apple.)

1.macOS 10.14(Beta)
2.Xcode 10(Beta)

As you noticed, they are beta version which means there are some risks. Actually, the Anti Virus software I’m using doesn’t work on OS 10.14.

Xcode 10

Create a playground

Open Xcode beta and create a new project then choose blank.

Image for post
Image for post

When you open the project, you can see the following. If you click the button on the bottom, you will see “Hello, playground”.

Image for post
Image for post

Write code

import CreateMLUI 

let builder = MLImageClassifierBuilder()

Then, click the assistant editor and hit the button on the bottom.

Image for post
Image for post
Image for post
Image for post

You will see ImageClassifier UI.

Prepare Images

For training a model you need to collect images. In this case, I used Kanye and Kim. According to the article, we need 10 images at least. I collected 55 images manually. 45 for train and 10 for test.

Image for post
Image for post

Train image

Once you get image, what you need to do is drag and drop the train folder then wait a few minutes. In my case, it took 2 minutes (MacBookPro Late 2013 4GB Ram).

When you finish training, you need to drag & drop the test folder as well as the train folder.

Save the model

Finally, you can save the model. For doing that, you need to click “save” button.

The next article will be how to use the model we trained.

Written by

#CreativeCoding #Art #PhysicalComputing #IoT #MachineLearning #python #creativetech

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store