Turning a Python-coded neural net into an iOS .mlmodel

Image for post
Image for post

So you’ve got your Keras model set up, and it can do everything you want it to do. But how do you get it onto an iOS device? Thanks to Apple’s Core ML library, this process is painless and can be done in less than 10 lines of code. Better yet, once you write the code I’ll show you below, there’s very little you’ll have to change for the next time you need to convert a model. Here’s a link to the GitHub repo:

Now let’s begin!

Overview

Before we start, what does the whole process look like? …


Using the Min-conflicts AI algorithm to quickly solve N-Queens

Image for post
Image for post
One Solution for N = 8 Queens

N-Queens is a famous computer science problem. The goal is to place “N” Number of queens on an “N x N” sized chess board such that no queen is under attack by another queen. There’s plenty of solutions to this problem, but there’s one particular algorithm which is my favorite: Min-Conflicts. Min-conflicts will randomly choose a queen, and move it to a place on the board where there are less conflicting queens than there are now. If there is no such spot, it will pick another random queen and continue to iterate. Seems pretty simple right?


What used to take days, now takes minutes. Thank you Apple

Image for post
Image for post
Cat or Dog?

Let’s take 5 minutes to make an iOS image classifier to classify cats and dogs. Naturally, this can be extended to classify anything, but come on, cats and dogs are a cute start.

The first thing we’re going to do is make two folders on our desktop: one titled “Training Data” and the other titled “Testing Data”. Make sure that the spelling on these two folders, and all of the following folders, match exactly mine or you will encounter some cryptic error messages.


Determining people’s feelings from real tweets

Image for post
Image for post
Let’s quickly teach a computer to understand the English language

An iOS and MacOS Natural language processing model for determining people’s feelings can be implemented and exported extremely easily using Apple’s CreateML library and text from people’s past tweets. Let’s download the data and test it out!

After unzipping the data from the link above, drag and drop the .csv file in to somewhere convenient. Next, open up a playground on Xcode, select MacOS, and select a blank file.


Image for post
Image for post
A Journey of a 1000 miles begins with a single step

I haven’t seen a list that nicely formulates the steps needed to go from beginner to practitioner in machine learning for free, so I created this post. Machine learning is a very very big field that’s having explosive growth right now due to the recent advances in hardware and the resurgence of some key ideas. However, none of this is particularly useful if you just wanna get started and make something cool like an image detection program. I want to stress that the list below is if you’re trying to use the machine learning knowledge you learn for something practical rather than theoretical. Believe me, there’s a big difference. …

About

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