Machine Learning for Mobile

Book description

Leverage the power of machine learning on mobiles and build intelligent mobile applications with ease

Key Features

  • Build smart mobile applications for Android and iOS devices
  • Use popular machine learning toolkits such as Core ML and TensorFlow Lite
  • Explore cloud services for machine learning that can be used in mobile apps

Book Description

Machine learning presents an entirely unique opportunity in software development. It allows smartphones to produce an enormous amount of useful data that can be mined, analyzed, and used to make predictions. This book will help you master machine learning for mobile devices with easy-to-follow, practical examples.

You will begin with an introduction to machine learning on mobiles and grasp the fundamentals so you become well-acquainted with the subject. You will master supervised and unsupervised learning algorithms, and then learn how to build a machine learning model using mobile-based libraries such as Core ML, TensorFlow Lite, ML Kit, and Fritz on Android and iOS platforms. In doing so, you will also tackle some common and not-so-common machine learning problems with regard to Computer Vision and other real-world domains.

By the end of this book, you will have explored machine learning in depth and implemented on-device machine learning with ease, thereby gaining a thorough understanding of how to run, create, and build real-time machine-learning applications on your mobile devices.

What you will learn

  • Build intelligent machine learning models that run on Android and iOS
  • Use machine learning toolkits such as Core ML, TensorFlow Lite, and more
  • Learn how to use Google Mobile Vision in your mobile apps
  • Build a spam message detection system using Linear SVM
  • Using Core ML to implement a regression model for iOS devices
  • Build image classification systems using TensorFlow Lite and Core ML

Who this book is for

If you are a mobile app developer or a machine learning enthusiast keen to use machine learning to build smart mobile applications, this book is for you. Some experience with mobile application development is all you need to get started with this book. Prior experience with machine learning will be an added bonus

Table of contents

  1. Title Page
  2. Copyright and Credits
    1. Machine Learning for Mobile
  3. About Packt
    1. Why subscribe?
  4. Contributors
    1. About the authors
    2. About the reviewer
    3. Packt is searching for authors like you
  5. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
      1. Download the example code files
      2. Download the color images
      3. Conventions used
    4. Get in touch
      1. Reviews
  6. Introduction to Machine Learning on Mobile
    1. Definition of machine learning
      1. When is it appropriate to go for machine learning systems?
    2. The machine learning process
      1. Defining the machine learning problem
      2. Preparing the data
      3. Building the model
        1. Selecting the right machine learning algorithm
        2. Training the machine learning model
        3. Testing the model
        4. Evaluation of the model
      4. Making predictions/Deploying in the field
    3. Types of learning
      1. Supervised learning
      2. Unsupervised learning
      3. Semi-supervised learning
      4. Reinforcement learning
      5. Challenges in machine learning
    4. Why use machine learning on mobile devices?
      1. Ways to implement machine learning in mobile applications
        1. Utilizing machine learning service providers for a machine learning model
        2. Ways to train the machine learning model
          1. On a desktop (training in the cloud)
          2. On a device
        3. Ways to carry out the inference – making predictions
          1. Inference on a server
          2. Inference on a device
      2. Popular mobile machine learning tools and SDKs
      3. Skills needed to implement on-device machine learning
    5. Summary
  7. Supervised and Unsupervised Learning Algorithms
    1. Introduction to supervised learning algorithms
    2. Deep dive into supervised learning algorithms
      1. Naive Bayes
      2. Decision trees
      3. Linear regression
      4. Logistic regression
      5. Support vector machines
      6. Random forest
    3. Introduction to unsupervised learning algorithms
    4. Deep dive into unsupervised learning algorithms
      1. Clustering algorithms
        1. Clustering methods
          1. Hierarchical agglomerative clustering methods
          2. K-means clustering
      2. Association rule learning algorithm
    5. Summary
    6. References
  8. Random Forest on iOS
    1. Introduction to algorithms
      1. Decision tree 
        1. Advantages of the decision tree algorithm
        2. Disadvantages of decision trees
        3. Advantages of decision trees
      2. Random forests
    2. Solving the problem using random forest in Core ML
      1. Dataset
        1. Naming the dataset
      2. Technical requirements
      3. Creating the model file using scikit-learn 
      4. Converting the scikit model to the Core ML model
      5. Creating an iOS mobile application using the Core ML model
    3. Summary
    4. Further reading
  9. TensorFlow Mobile in Android
    1. An introduction to TensorFlow
      1. TensorFlow Lite components
        1. Model-file format
        2. Interpreter
        3. Ops/Kernel
        4. Interface to hardware acceleration
    2. The architecture of a mobile machine learning application
      1. Understanding the model concepts
    3. Writing the mobile application using the TensorFlow model
      1. Writing our first program
        1. Creating and Saving the TF model
        2. Freezing the graph
        3. Optimizing the model file
      2. Creating the Android app
        1. Copying the TF Model
        2. Creating an activity
    4. Summary
  10. Regression Using Core ML in iOS
    1. Introduction to regression
      1. Linear regression
        1. Dataset
        2. Dataset naming
    2. Understanding the basics of Core ML
    3. Solving the problem using regression in Core ML
      1. Technical requirements
      2. How to create the model file using scikit-learn
      3. Running and testing the model
      4. Importing the model into the iOS project
      5. Writing the iOS application
      6. Running the iOS application
    4. Further reading
    5. Summary
  11. The ML Kit SDK
    1. Understanding ML Kit
      1. ML Kit APIs
        1. Text recognition
        2. Face detection
        3. Barcode scanning
        4. Image labeling
        5. Landmark recognition
        6. Custom model inference
    2. Creating a text recognition app using Firebase on-device APIs
    3. Creating a text recognition app using Firebase on-cloud APIs
    4. Face detection using ML Kit
      1. Face detection concepts
      2. Sample solution for face detection using ML Kit
      3. Running the app
    5. Summary
  12. Spam Message Detection
    1. Understanding NLP
      1. Introducing NLP
      2. Text-preprocessing techniques
        1. Removing noise
        2. Normalization
        3. Standardization
      3. Feature engineering
        1. Entity extraction
        2. Topic modeling
        3. Bag-of-words model
        4. Statistical Engineering
        5. TF–IDF
        6. TF
        7. Inverse Document Frequency (IDF)
        8. TF-IDF
      4. Classifying/clustering the text
    2. Understanding linear SVM algorithm
    3. Solving the problem using linear SVM in Core ML
      1. About the data
      2. Technical requirements
      3. Creating the Model file using Scikit Learn 
      4. Converting the scikit-learn model into the Core ML model
      5. Writing the iOS application
    4. Summary
  13. Fritz
    1. Introduction to Fritz
      1. Prebuilt ML models
      2. Ability to use custom models
      3. Model management
    2. Hand-on samples using Fritz
      1. Using the existing TensorFlow for mobile model in an Android application using Fritz
        1. Registering with Fritz
        2. Uploading the model file (.pb or .tflite)
        3. Setting up Android and registering the app
        4. Adding Fritz's TFMobile library
        5. Adding dependencies to the project
        6. Registering the FritzJob service in your Android Manifest
        7. Replacing the TensorFlowInferenceInterface class with Fritz Interpreter
        8. Building and running the application
        9. Deploying a new version of your model
      2. Creating an android application using fritz pre-built models
        1. Adding dependencies to the project
        2. Registering the Fritz JobService in your Android Manifest
        3. Creating the app layout and components
        4. Coding the application
      3. Using the existing Core ML model in an iOS application using Fritz
        1. Registering with Fritz
        2. Creating a new project in Fritz
        3. Uploading the model file (.pb or .tflite)
        4. Creating an Xcode project
        5. Installing Fritz dependencies
        6. Adding code
        7. Building and running the iOS mobile application
    3. Summary
  14. Neural Networks on Mobile
    1. Introduction to neural networks
      1. Communication steps of  a neuron
      2. The activation function
      3. Arrangement of neurons
      4. Types of neural networks
    2. Image recognition solution
    3. Creating a TensorFlow image recognition model
      1. What does TensorFlow do?
      2. Retraining the model
        1. About bottlenecks
      3. Converting the TensorFlow model into the Core ML model
      4. Writing the iOS mobile application
    4. Handwritten digit recognition solution
    5. Introduction to Keras
    6. Installing Keras
    7. Solving the problem
      1. Defining the problem statement
      2. Problem solution
        1. Preparing the data
        2. Defining the model's architecture
        3. Compiling and fitting the model
        4. Converting the Keras model into the Core ML model
        5. Creating the iOS mobile application
    8. Summary
  15. Mobile Application Using Google Vision
    1. Features of Google Cloud Vision
    2. Sample mobile application using Google Cloud Vision
      1. How does label detection work?
      2. Prerequisites
      3. Preparations
      4. Understanding the Application
      5. Output
    3. Summary
  16. The Future of ML on Mobile Applications
    1. Key ML mobile applications 
      1. Facebook
      2. Google Maps
      3. Snapchat
      4. Tinder
      5. Netflix
      6. Oval Money
      7. ImprompDo
      8. Dango
      9. Carat
      10. Uber
      11. GBoard
    2. Key innovation areas
      1. Personalization applications
      2. Healthcare
      3. Targeted promotions and marketing
      4. Visual and audio recognition
      5. E-commerce 
      6. Finance management
      7. Gaming and entertainment
      8. Enterprise apps
      9. Real estate
      10. Agriculture
      11. Energy
      12. Mobile security
    3. Opportunities for stakeholders
      1. Hardware manufacturers
      2. Mobile operating system vendors
      3. Third-party mobile ML SDK providers
      4. ML mobile application developers
    4. Summary
  17. Question and Answers
    1. FAQs
      1. Data science
        1. What is data science?
        2. Where is data science used?
        3. What is big data?
        4. What is data mining?
        5. Relationship between data science and big data
        6. What are artificial neural networks?
        7. What is AI?
        8. How are data science, AI, and machine learning interrelated?
      2. Machine learning framework 
        1. Caffe2
        2. scikit-learn
        3. TensorFlow
        4. Core ML
      3. Mobile machine learning project implementation
        1. What are the high-level important items to be considered before starting the project?
        2. What are the roles and skills required to implement a mobile machine learning project?
        3.  What should you focus on when testing the mobile machine learning project?
        4. What is the help that the domain expert will provide to the machine learning project?
        5. What are the common pitfalls in machine learning projects?
      4. Installation
        1. Python
        2. Python dependencies
        3. Xcode
    2. References 
  18. Other Books You May Enjoy
    1. Leave a review - let other readers know what you think

Product information

  • Title: Machine Learning for Mobile
  • Author(s): Revathi Gopalakrishnan, Avinash Venkateswarlu
  • Release date: December 2018
  • Publisher(s): Packt Publishing
  • ISBN: 9781788629355