Version Second Edition
Platform iOS 13
Language Swift 5.1
Editor Xcode 11

Get started with Machine Learning for Apple and iOS!

Want to know a secret? Machine learning isn’t really that hard to learn. The truth is, you don’t need a PhD from a prestigious university or a background in mathematics to do machine learning. If you already know how to code, you can pick up machine learning quite easily — promise!

This book will get you started with machine learning on iOS and Apple devices. The first bit is a gentle introduction to the world of machine learning and what it has to offer — as well as what its limitations are. In the rest of the book, you’ll look at each of these topics in more detail, until you know enough to make machine learning a useful tool in your software development toolbox.

There are now several high-level Apple frameworks, including Natural Language, Speech, and Vision, that provide advanced machine learning functionality behind simple APIs as part of Apple’s iOS tooling. Whether you want to convert speech to text, recognize language or grammatical structure, detect faces in photos or track moving objects in video, these frameworks have got you covered.

In this book, you’ll learn how to use these tools and frameworks to make your apps smarter. Even better, you’ll learn how machine learning works behind the scenes — and why this technology is awesome.

This book is for all Apple and iOS developers who are interested in learning how to train models, code image recognition systems, learn how natural language processing works, build sequence classifiers and more.

Before You Begin

This section tells you a few things you need to know before you get started, such as what you’ll need for hardware and software, where to find the project files for this book, and more.

i

iii

Section I: Machine Learning with Images

This section introduces you to the world of machine learning. You’ll get a high level view of what it is, and how it can be used on mobile. You’ll also get a quick primer on using Python for machine learning. You’ll learn how to set up an environment to use tools such as CreateML, Turi Create, and Keras for machine learning. Finally, you’ll learn how to use machine learning techniques to solve problems using images. The topics you’ll explore include image classification, object detection with bounding boxes, and object segmentation.

In this introduction chapter, you’ll learn what machine learning is all about. You’ll touch on everything from, the difference between supervised and unsupervised learning, to what transfer learning is. You’ll even go over the ethics of machine learning, and how bias can affect models.

1

In this chapter, you’ll build your first iOS app by adding a CoreML model to detect whether a snack is healthy or unhealthy. You’ll focus on how machine learning can be used to solve classification problems such as trying to identify what an object might be.

2

In this chapter, you’ll start to build your first machine learning model using Create ML. You’ll be introduced to the dataset used to create the model, along with how Create ML uses transfer learning to get amazing classification results. Moreover, you’ll learn what it means to evaluate the performance of your model.

3

In this chapter, you’ll get a quick primer on Python. You’ll learn how to setup your Python environment using Conda, and how to install external libraries. You’ll learn how to run and use Jupyter notebooks to iterate quickly with Python.

4

In this chapter, you’ll learn to use Turi Create to build a classification model. You’ll use the snacks dataset to create your model. You’ll learn how to analyze your model’s performance, and how to go under the hood with Turi Create in order to improve your model.

5

In this chapter, you’ll learn to how to take control of your model’s training with Keras. You’ll design your first neural network, and how to pass your dataset into Keras for training.

6

In this chapter, you’ll learn why a simple neural network might not be enough when it comes to solving problems with images using machine learning. You’ll learn about how using a convolutional neural network provides a better approach to solving classification problems.

7

In this chapter, you’ll learn about advanced model architectures used for solving image classification. You’ll learn how you can use Keras to do transfer learning, and how applying advanced techniques such as dropout and regularization can improve your model’s performance.

8

In this chapter, you’ll learn how to identify an object’s location in an image. You’ll learn how to build a simple localization model that predicts a single bounding box.

9

In this final chapter, you’ll learn about some advanced localization models. You’ll learn about one-shot detectors like YOLO and SSD and how they can be used to identify multiple objects in an image. You’ll also learn about how machine learning can be used for segmentation to separate an object from its background.

10

Section II: Machine Learning with Sequences

In this section, you’ll learn how to apply machine learning to sequential data. You’ll work on a new iOS app which attempts to identify a user’s activity using data from their iPhone’s motion sensors. In the process, you’ll learn how to build a good training dataset, how to create an activity classification model using Turi Create, and how to incorporate your model into an iOS app to support responsive classifications with real-time data.

In this chapter, you’ll learn how working with sequences differs from working with discrete data like individual images. You’ll learn how to collect iPhone sensor data, as well as what it takes to build a good training dataset.

11

In this chapter, you’ll learn about neural networks designed to work with sequences. You’ll also learn how to use Turi Create to train an activity classification model using data from the previous chapter.

12

In this chapter, you’ll learn how to pass real-time sequential data captured from a device’s motion sensors into your Core ML model. You’ll learn some tricks to help keep your apps responsive and accurate while processing sequences of streaming data.

13

Section III: Natural Language Processing

In this section, you’ll focus on a specific type of sequential data — natural language text. You’ll learn how to use Apple-provided APIs to perform common language processing tasks. You’ll also learn how to use text with neural networks, and you’ll create a model with Keras that translates text from Spanish to English. Finally, you’ll read about advanced techniques that you can experiment with to improve your model.

In this chapter, you’ll learn how to use Apple’s Natural Language framework to handle several useful text-related tasks. You’ll explore this API in the context of a movie review app that supports multiple languages.

14

In this chapter, you’ll learn about sequence-to-sequence models and how you can use them to do things like language translation. You’ll build a model with Keras that attempts to translate Spanish-language movie reviews into English.

15

This chapter introduces additional techniques you can use to improve the performance of your sequence-to-sequence models.

16

Meet the team

Contributors

Who is this book for

This books is for the intermediate iOS developer who already knows the basics of iOS and Swift development, but wants to understand how machine learning works.

Concepts covered in this book

  • CoreML
  • Create ML
  • Turi Create and Keras
  • Image Classification
  • Convolutional Networks
  • Sequence Classification
  • Text-to-text Transform

Version history

Second Edition · iOS 13, Swift 5.1, Xcode 11

v2.0 · May 19 2020 · Alexis Gallagher, Chris LaPollo, Audrey Tam & Matthijs Hollemans
Pro

Machine Learning by Tutorials

By Alexis Gallagher, Chris LaPollo, Audrey Tam and Matthijs Hollemans

The best book on machine learning for iOS. Covers CoreML, Vison, image and sequence classifiers, natural language processing, and more!

Read for Free with an Ultimate Pro Subscription* * Includes this and all other books in our online library See all benefits
Buy Individually $59.99* *Includes access to all of our online reading features.
See buying options
Hide buying options

All videos. All books.
One low price.

A raywenderlich.com subscription is the best way to learn and master mobile development — plans start at just $19.99/month!

Learn iOS, Swift, Android, Kotlin, Flutter and Dart development and unlock our massive catalog of 50+ books and 4,000+ videos.