Before you go, check out these stories!

0
Hackernoon logoTraining Custom Models Using Turi Create by@azamsharp

Training Custom Models Using Turi Create

Author profile picture

@azamsharpMohammad Azam

https://tctechcrunch2011.files.wordpress.com/2015/02/shutterstock_175625024.jpg

In my last post I talked about Integrating TensorFlow Models into an iOS App. We used the tfcoreml tool to perform the conversion between models. Although tfcoreml tool is a powerful tool but it is not very developer friendly. The lack of documentation and the wild goose chases to find the correct operators to make your model work requires a lot of time and effort.

Recently, Apple released a tool called Turi Create which is capable of training custom machine learning models. This means you can develop models which can identify different members of your family, provided you train the model using a lot of imagesโ€ฆ a lot.

Instead of identifying family members I will be focusing on cats and dogs, also known as members of the extended family. We will build a custom model which can identify whether an image is of a cat or a dog.

Downloading Images of Cats andย Dogs

The first step is to download a lot of images of cats and dogs. This is necessary because we will be using the images to train our custom model. Instead of downloading images from Google Images which might take eternity, we can utilize the services like ImageNet. Go to ImageNet and search for cat. This will bring up a lot of different results. We selected โ€œtrue catโ€ which will take you to a new page where you can download the URLs for all the cat images.

NOTE: Even though you can successfully create an account on ImageNet but you will still not get permission to download the actual images. You must download the URLs.

Go ahead and download the URLs for cat and dog dataset. Now, that you have the URLs for your dataset we need to download the images associated with each URL.

I wrote a simple Python script which read the URLs from a file and then download the images into the folder specified by the variables in the script as shown below. I am not an expert in Python language but the script below works for now!

Go to the terminal and execute the script.

python download_images.py

This will start downloading the images into the designated folders as shown below:

The process of downloading all the images will take a while! To be honest after 5โ€“8 minutes I forcefully stopped the script. Repeat the same process for dog URLs and make sure you are putting the images in their respective folder i.e cat images in โ€œcatโ€ folder and dog images in โ€œdogโ€ folder.

Once the images have been downloaded we are ready to tag and train our custom model to identify dogs and cats.

Tagging and Trainingย Model

Before we start training our model we first need to tag the pictures whether they are โ€œcatโ€ or โ€œdogโ€. Luckily, Turi Create documentation includes all the necessary code to successfully tag images based on different folders.

The last line data.explore() will even open up a Turi Create Image Visualizer where you can see the images along with their tags. Now that we have tagged our images it is time to train them.

Fortunately, all the code to train a model is provided in Turi Create documentation. Thank you very much!ย :)

After training the model we exported it to Core ML format, which allows us to integrate it into our iOS application.

Integrating Model into iOS Application

I already have an app setup which goes through a list of images and predict each image. Simply, drag and drop the model along with some untagged images and you are good to go. I went back to the ImageNet and downloaded a separate dataset which contained images of dogs and cats. I did that because I did not wanted to use the same dataset which was used to train the model. Here is the screenshot of several images added to the Xcode project for testing the new model.

The result is shown below:

I hope you like the article!

References

If you want to support my articles then please check out my Udemy courses on www.azamsharp.com. All Udemy courses already have a $10 coupon attached to them. I hope you enjoy the courses.

Tags

Join Hacker Noon

Create your free account to unlock your custom reading experience.