Book Image

Machine Learning Projects for Mobile Applications

By : Karthikeyan NG
Book Image

Machine Learning Projects for Mobile Applications

By: Karthikeyan NG

Overview of this book

Machine learning is a technique that focuses on developing computer programs that can be modified when exposed to new data. We can make use of it for our mobile applications and this book will show you how to do so. The book starts with the basics of machine learning concepts for mobile applications and how to get well equipped for further tasks. You will start by developing an app to classify age and gender using Core ML and Tensorflow Lite. You will explore neural style transfer and get familiar with how deep CNNs work. We will also take a closer look at Google’s ML Kit for the Firebase SDK for mobile applications. You will learn how to detect handwritten text on mobile. You will also learn how to create your own Snapchat filter by making use of facial attributes and OpenCV. You will learn how to train your own food classification model on your mobile; all of this will be done with the help of deep learning techniques. Lastly, you will build an image classifier on your mobile, compare its performance, and analyze the results on both mobile and cloud using TensorFlow Lite with an RCNN. By the end of this book, you will not only have mastered the concepts of machine learning but also learned how to resolve problems faced while building powerful apps on mobiles using TensorFlow Lite, Caffe2, and Core ML.
Table of Contents (16 chapters)
Title Page
Dedication
Packt Upsell
Contributors
Preface
Index

The implementation on iOS using Core ML


It is now time to jump into the coding part of the application. We are using a model developed using the Caffe deep learning framework by Berkeley AI Research (BAIR) team as well as the community of contributors. As a first step, we need to convert the existing Caffe models into Core ML models to be utilized in our application:

//Downloading Age and Gender models 
wget 
 http://www.openu.ac.il/home/hassner/projects/cnn_agegender/cnn_age_gen
        der_models_and_data.0.0.2.zip
unzip -a cnn_age_gender_models_and_data.0.0.2.zip

Now, go to the extracted folder and convert the model into a Core ML model:

import coremltools

folder = 'cnn_age_gender_models_and_data.0.0.2'

coreml_model = coremltools.converters.caffe.convert(
 (folder + '/age_net.caffemodel', folder + '/deploy_age.prototxt'),
  image_input_names = 'data',
  class_labels = 'ages.txt'
)

coreml_model.save('Age.mlmodel')

The same needs to be done for the gender model as well. To kick start our...