Source: Deep Learning on Medium
How to create your own image classifier model with Create ML
Create ML was introduced in last year’s WWDC as a framework integrated into Swift Playgrounds. It allows you to train & create your own models. Which you then can use in your projects and perform predictions using Core ML.
Prepare your dataset
Before we begin we need to prepare our dataset. For image classification you need 2 folders, Training data & Test data. Inside those folders are other folders with the name of a class/label. This folder contains all images of that certain label. According to Apple 10 images will already do for a certain label, but the more the better!
Create a project
If you have MacOS Catalina & Xcode 11 you can use the Create ML app inside Xcode. You can find it under Xcode > Open developer tool > Create ML. This has an easy to use interface. If you don’t have MacOS Catalina, you can use Create ML in an Xcode playground-file. For this example I’m using the playground:
First create a playground file, choose a blank page from MacOS tab. Then insert these 3 lines in the editor.
import CreateMLUIlet builder = MLImageClassifierBuilder()
This will open a tab in playground.
Train the model
Next up is training the model by simply dragging your training data folder in the playground. You can choose to augmentize the training by choosing to also crop, blur, rotate, … This will make the training a bit longer but it’ll also result in better accuracy.
When it’s done training, you drag the test data inside the playground and after a few seconds (depending how large your test data is) your done!
You save the model by simply dragging it so a different folder. Now you have your own Machine Learning model you can use in your projects!
It’s really easy to create a model with Create ML! Now, I have tested this with a small dataset of around 200 pictures of 2 classes (dogs and cats). So I don’t know how it will perform with larger datasets. That’s something I’ll be testing the coming days!