CreateML: Train Object Detection from Scratch

Updated on Dec 27,2023

CreateML: Train Object Detection from Scratch

Table of Contents

  1. Introduction
  2. Collecting Data
  3. Labelling Data
  4. Training the Model
  5. Testing the Model
  6. Exporting the Model
  7. Integrating the Model into an iOS App
  8. Conclusion

Introduction

In this tutorial, I will guide You on how to use Create ML and other tools to create an object detection model from scratch. We will then export this model and use it in an iOS app to detect objects in provided photos. So let's dive into the code and get started!

Collecting Data

Before we begin, it is important to decide what kind of objects we want to detect in photos. For this tutorial, we will focus on the three most popular road signs in Poland. According to Apple's guidelines, it is recommended to Collect a minimum of 30 photos for each object we want to detect. The more photos, the better the training results. It is also important to have a balanced amount of data for each class to avoid biased training results.

To find training data, we can simply use Google and search for images of road signs in Poland. Once we have found the images, we can download them and store them in a folder for further processing.

Labelling Data

After collecting the data, the next step is to label it. Unfortunately, Apple does not provide a built-in tool for data labelling. However, there is a free online tool called "IBM Cloud Annotations" developed by Nick Bull Decos. To use this tool, we need to create an account on Hacker Noon and log in using IBM Cloud.

Once logged in, we can create a new project and import the collected photos. We then need to annotate the photos by creating different classes for each road sign. The tool also allows us to label multiple road signs in one photo. After labelling all the photos, we can export the annotations in the Create ML format as a JSON file.

Training the Model

Now that we have collected and labelled the data, it's time to train our object detection model using Create ML. In the Create ML app, we create a new project and choose the object detector model. We give it a name, such as "RoadSignDetector", and save the project.

The cool thing about Create ML is that it is a drag-and-drop tool. We simply need to drag and drop the annotations JSON file we exported from IBM Cloud Annotations into Create ML. We then click on the "Train" button and the training process begins.

Training the model can take a significant amount of time, depending on the size of the dataset and the computer's processing power. It is recommended to leave the training process running overnight or when you don't need to use the computer.

Testing the Model

After the training process is complete, we can verify the quality of the model using the testing images. These testing images should be different from the ones used for training. In Create ML, we can drag and drop the testing images and see how well the model detects the road signs.

Exporting the Model

Once We Are satisfied with the performance of the model, we can export it. Create ML allows us to export the model as a Core ML model, which can be easily integrated into iOS apps. We can either use the "Share" option in Create ML to export the model directly to Xcode or save it locally and import it into Xcode manually.

Integrating the Model into an iOS App

To integrate the exported model into an iOS app, we need to open Xcode and create a new project. We then add a UIImageView and a UIButton to the storyboard, along with the necessary code to handle the image picker and display the detected objects.

In the code, we load the Core ML model using the name we gave it during the training process. We then use the model to perform object detection on the selected photo. The detections are displayed on the photo, along with their confidence scores.

Conclusion

Congratulations! You have successfully created an object detection model from scratch using Create ML and integrated it into an iOS app. Object detection is a powerful technique that can be used in a wide range of applications. Feel free to experiment with different datasets and explore the possibilities of machine learning.

Pros

  • Create ML is a user-friendly tool that makes it easy to train object detection models.
  • The integration of the model into an iOS app allows for real-time object detection on mobile devices.
  • Collecting and labelling data can be done using freely available online tools.

Cons

  • Training a model can be time-consuming, especially with large datasets.
  • The accuracy of the model depends on the quality and diversity of the training data.
  • Apple's Create ML tool is only available for macOS.

Highlights

  • Learn how to collect and label data for object detection.
  • Train an object detection model using Create ML.
  • Export the trained model and integrate it into an iOS app.
  • Test the model's performance and make improvements if necessary.

FAQ

Q: Can I use Create ML on Windows or Linux? A: No, Create ML is only available for macOS.

Q: How many training images do I need for good results? A: It is recommended to have a minimum of 30 images per class, but more images generally lead to better results.

Q: Can I use the model trained in Create ML on Android devices? A: No, the Create ML models are exported as Core ML models, which are specific to Apple's platforms.

Q: Can I use Create ML to train models for other types of tasks, like image classification or text recognition? A: Yes, Create ML supports various types of machine learning tasks, including image classification, text recognition, and more.

Most people like