Introducing Apple’s Game-Changing Machine Learning Frameworks — CoreML and CreateML
My Journey Developing “WoofWonder” to detect dog breeds with Apple Machine Learning
Introduction to Machine Learning
Machine learning (ML) has become a driving force in technology, enabling remarkable advancements in artificial intelligence. Apple, renowned for its innovative products and seamless user experiences, has fully embraced the power of ML in its ecosystem. From personalized experiences to advanced image recognition, object detection, text classification, sound classification, etc, Apple’s integration of ML technologies has transformed the way we interact with their devices. Thanks to their outstanding framework, which are CoreML and CreateML. So, this article provides an introduction to machine learning in the Apple environment, exploring its applications, key technologies, and the impact it has on enhancing user experiences.
What is CoreML?
CoreML stands for Core Machine Learning, and it’s a framework developed by Apple Inc. CoreML is specifically designed for integrating machine learning models into applications developed for Apple platforms such as iOS, macOS, watchOS, and tvOS. It provides a seamless way to integrate and run machine learning models on Apple devices.
The main purpose of CoreML is to simplify the process of incorporating machine learning capabilities into iOS and macOS applications. It allows developers to leverage pre-trained machine learning models and deploy them directly on Apple devices, enabling tasks such as image recognition, natural language processing, and other forms of data analysis.
What is CreateML?
CreateML is a framework developed by Apple Inc. as part of their machine learning ecosystem. It is specifically designed to enable developers to create and train custom machine learning models on Apple platforms such as macOS and iOS. CreateML provides a user-friendly interface and a simplified workflow for building machine learning models without requiring extensive knowledge of machine learning algorithms or programming.
The main goal of CreateML is to empower developers to create models tailored to their specific use cases, leveraging the power of machine learning to solve problems and enhance applications. It focuses on tasks such as image classification, object detection, sound analysis, and natural language processing.
What’s the difference between CoreML & CreateML?
Basically, CoreML and CreateML are complementing each other because it has a same purpose. In a simple way, the difference between them is CoreML is the model that has been trained with CreateML and will be integrated in an apps. So basically CoreML is the model created, and CreateML is the tools to create a ML model along with its types, training, validating, and testing the datasets.
How to make a machine learning model with CreateML?
These are the steps to create and train a machine learning model:
- Ensure you have Xcode installed on your macOS system, because CreateML is in the package of Xcode, and then create a new project.
2. Open the CreateML tools on your macOS, and then select the machine learning template or types that you want to use or implement onto your apps. In my case, i will choose Image Classification.
3. Prepare the dataset that you want to train and will be used on your apps. If you want to implement Image Classification as your model, then you need to prepare Image Dataset, or if you need Text Classification as your model, then you need to prepare Text Dataset (csv, txt, etc).
4. Split and assign the dataset that you’ve been prepare before. In this moment, you need to split your data into Training Data, Validation Data, and Testing Data that has been classified into several classes that you want. I classified my data as 32 classes with 6107 items, so it has 32 different breeds of dog.
5. Tune the parameter of the model after you split the dataset. You could tune the iterations of the training and the augmentation. In my model, i tune the iterations to 150 iterations and i checked Flip and Rotate in my augmentations. Flip augmentation will generates additional image by flipping the original images, and the Rotate augmentation will generates additional image by randomly rotating the original image.
6. After all things set, train the dataset. It takes time depends on number of the classes, the quantity of the data, and the augmentations. It takes about an hour for me to train the model. Actually, it took me several try until i’ve got the best model that i want (i’ve trained 5 different model and it tooks about 6 hour overall). As you could see below, i’ve got 99.2% Training Accuracy and 95.7% Validation Accuracy.
7. After the training done, you could see the evaluation of the training, validating, and the testing result. You also can see the preview of the model prediction, as in the image below. As we can see, it has a good accuracy and could predict the input accurately.
8. Export the model that has been trained from the Output menu. After you open the output menu, choose the Get button, and then save the model. The model exported will be Core ML Model (mlmodel extension). And that’s it for the Machine Learning Model.
How to integrate Machine Learning to Swift with UIKit?
There are many ways to integrate the CoreML Model, whether with SwiftUI or with UIKit. In my app, i use UIKit on its implementation. I will not go into too much detail. For the further detail about how to implement it, Apple provide the documentation of the implementation of Image Classification with UIKit. Here are the link if you want to know further about the implementation and the code that has been made by Apple.
Sneak peak of WoofWonder
WoofWonder is an app that implement Machine Learning Technology, that could detect and distinguish dog breed based on user’s input, so it could help people, whether dog lovers or not to distinguish dog breed. User just need to take a picture of a dog or just open image from their gallery, and it will show the prediction.
The app is designed for someone who has interest in a dog world, whether a dog lovers or not, who has wonder about the breed of a random dog they found on internet, or a random dog that they found on the street, or their friend’s dog, or even their own dog. With this app, it will stop their habit to random guessing a dog breeds without any knowledge, and could be use anywhere, anytime. So goodbye to guessing games.
Here’s the preview of WoofWonder app.