Discover millions of ebooks, audiobooks, and so much more with a free trial

From $11.99/month after trial. Cancel anytime.

Machine Learning Projects for Mobile Applications: Build Android and iOS applications using TensorFlow Lite and Core ML
Machine Learning Projects for Mobile Applications: Build Android and iOS applications using TensorFlow Lite and Core ML
Machine Learning Projects for Mobile Applications: Build Android and iOS applications using TensorFlow Lite and Core ML
Ebook445 pages2 hours

Machine Learning Projects for Mobile Applications: Build Android and iOS applications using TensorFlow Lite and Core ML

Rating: 0 out of 5 stars

()

Read preview

About this ebook

Bring magic to your mobile apps using TensorFlow Lite and Core ML




Key Features



  • Explore machine learning using classification, analytics, and detection tasks.


  • Work with image, text and video datasets to delve into real-world tasks


  • Build apps for Android and iOS using Caffe, Core ML and Tensorflow Lite





Book Description



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.




What you will learn



  • Demystify the machine learning landscape on mobile


  • Age and gender detection using TensorFlow Lite and Core ML


  • Use ML Kit for Firebase for in-text detection, face detection, and barcode scanning


  • Create a digit classifier using adversarial learning


  • Build a cross-platform application with face filters using OpenCV


  • Classify food using deep CNNs and TensorFlow Lite on iOS



Who this book is for



Machine Learning Projects for Mobile Applications is for you if you are a data scientist, machine learning expert, deep learning, or AI enthusiast who fancies mastering machine learning and deep learning implementation with practical examples using TensorFlow Lite and CoreML. Basic knowledge of Python programming language would be an added advantage.

LanguageEnglish
Release dateOct 31, 2018
ISBN9781788998468
Machine Learning Projects for Mobile Applications: Build Android and iOS applications using TensorFlow Lite and Core ML

Related to Machine Learning Projects for Mobile Applications

Related ebooks

Intelligence (AI) & Semantics For You

View More

Related articles

Reviews for Machine Learning Projects for Mobile Applications

Rating: 0 out of 5 stars
0 ratings

0 ratings0 reviews

What did you think?

Tap to rate

Review must be at least 10 words

    Book preview

    Machine Learning Projects for Mobile Applications - Karthikeyan NG

    Machine Learning Projects for Mobile Applications

    Machine Learning Projects for Mobile Applications

    Build Android and iOS applications using TensorFlow Lite and Core ML

    Karthikeyan NG

    BIRMINGHAM - MUMBAI

    Machine Learning Projects for Mobile Applications

    Copyright © 2018 Packt Publishing

    All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.

    Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing or its dealers and distributors, will be held liable for any damages caused or alleged to have been caused directly or indirectly by this book.

    Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.

    Commissioning Editor: Sunith Shetty 

    Acquisition Editor: Dayne Castelino

    Content Development Editor: Rhea Henriques

    Technical Editor: Sayli Nikalje

    Copy Editor: Safis Editing

    Project Coordinator: Manthan Patel

    Proofreader: Safis Editing

    Indexer: Mariammal Chettiyar

    Graphics: Jisha Chirayil

    Production Coordinator: Aparna Bhagat

    First published: October 2018

    Production reference: 1311018

    Published by Packt Publishing Ltd.

    Livery Place

    35 Livery Street

    Birmingham

    B3 2PB, UK.

    ISBN 978-1-78899-459-0

    www.packtpub.com

    To my wife, Nanthana, for putting up with me during the course of this book. I know it must not have been easy.

    To my parents, for their constant support.

    mapt.io

    Mapt is an online digital library that gives you full access to over 5,000 books and videos, as well as industry leading tools to help you plan your personal development and advance your career. For more information, please visit our website.

    Why subscribe?

    Spend less time learning and more time coding with practical eBooks and Videos from over 4,000 industry professionals

    Improve your learning with Skill Plans built especially for you

    Get a free eBook or video every month

    Mapt is fully searchable

    Copy and paste, print, and bookmark content

    Packt.com

    Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.packt.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at [email protected] for more details.

    At www.packt.com, you can also read a collection of free technical articles, sign up for a range of free newsletters, and receive exclusive discounts and offers on Packt books and eBooks. 

    Contributors

    About the author

    Karthikeyan NG is the Head of Engineering and Technology at the Indian lifestyle and fashion retail brand. He served as a software engineer at Symantec Corporation and has worked with two US-based startups as an early employee and has built various products. He has 9+ years of experience in various scalable products using Web, Mobile, ML, AR, and VR technologies. He is an aspiring entrepreneur and technology evangelist. His interests lie in exploring new technologies and innovative ideas to resolve a problem. He has also bagged prizes from more than 15 hackathons, is a TEDx speaker and a speaker at technology conferences and meetups as well as guest lecturer at a Bengaluru University. When not at work, he is found trekking.

    I would like to thank Saurav Satpathy for helping me with the codes in one of the chapters. I would like to extend my gratitude to Varsha Shetty for presenting the idea of the book, and to Rhea Henriques for her tenacity. Thanks to Akshi, Tejas, Sayli, and the technical reviewer, Mayur, and the editorial team. I would also like to thank the open source community for making this book possible with the frameworks on both Android and iOS platforms.

    About the reviewer

    Mayur Ravindra Narkhede has a good blend of experience in data science and industrial domain. He is a researcher with a B.Tech in computer science and an M.Tech in CSE with a specialization in Artificial Intelligence.

    A data scientist whose core experience lies in building automated end-to-end solutions, he

    is proficient at applying technology, AI, ML, data mining, and design thinking to better

    understand and predict improvements in business functions and desirable requirements

    with growth profitability.

    He has worked on multiple advanced solutions, such as ML and predictive model

    development for the oil and gas industry, financial services, road traffic and transport, life

    sciences, and the big data platform for asset-intensive industries.

    Packt is searching for authors like you

    If you're interested in becoming an author for Packt, please visit authors.packtpub.com and apply today. We have worked with thousands of developers and tech professionals, just like you, to help them share their insight with the global tech community. You can make a general application, apply for a specific hot topic that we are recruiting an author for, or submit your own idea.

    Table of Contents

    Title Page

    Copyright and Credits

    Machine Learning Projects for Mobile Applications

    Dedication

    Packt Upsell

    Why subscribe?

    Packt.com

    Contributors

    About the author

    About the reviewer

    Packt is searching for authors like you

    Preface

    Who this book is for

    What this book covers

    To get the most out of this book

    Download the code

    Download the color images

    Conventions used

    Get in touch

    Reviews

    Mobile Landscapes in Machine Learning

    Machine learning basics

    Supervised learning

    Unsupervised learning

    Linear regression - supervised learning

    TensorFlow Lite and Core ML

    TensorFlow Lite

    Supported platforms

    TensorFlow Lite memory usage and performance 

    Hands-on with TensorFlow Lite 

    Converting SavedModel into TensorFlow Lite format

    Strategies

    TensorFlow Lite on Android

    Downloading the APK binary

    TensorFlow Lite on Android Studio

    Building the TensorFlow Lite demo app from the source

    Installing Bazel

    Installing using Homebrew

    Installing Android NDK and SDK

    TensorFlow Lite on iOS

    Prerequisites

    Building the iOS demo app

    Core ML

    Core ML model conversion

    Converting your own model into a Core ML model

    Core ML on an iOS app

    Summary

    CNN Based Age and Gender Identification Using Core ML

    Age, gender, and emotion prediction

    Age prediction

    Gender prediction

    Convolutional Neural Networks 

    Finding patterns

    Finding features from an image

    Pooling layer

    Rectified linear units

    Local response normalization layer

    Dropout layer

    Fully connected layer

    CNNs for age and gender prediction

    Architecture

    Training the network

    Initializing the dataset

    The implementation on iOS using Core ML

    Summary

    Applying Neural Style Transfer on Photos

    Artistic neural style transfer

    Background

    VGG network

    Layers in the VGG network

    Building the applications

    TensorFlow-to-Core ML conversion

    iOS application

    Android application

    Setting up the model

    Training your own model

    Building the application

    Setting up the camera and an image picker 

    Summary

    References

    Deep Diving into the ML Kit with Firebase

    ML Kit basics

    Basic feature set

    Building the application

    Adding Firebase to our application

    Face detection

    Face orientation tracking

    Landmarks

    Classification

    Implementing face detection

    Face detector configuration

    Running the face detector

    Step one: creating a FirebaseVisionImage from the input

    Using a bitmap

    From media.Image

    From a ByteBuffer

    From a ByteArray

    From a file

    Step two: creating an instance of FirebaseVisionFaceDetector object

    Step three: image detection

    Retrieving information from detected faces

    Barcode scanner

    Step one: creating a FirebaseVisionImage object

    From bitmap

    From media.Image

    From ByteBuffer

    From ByteArray

    From file

    Step two: creating a FirebaseVisionBarcodeDetector object

    Step three: barcode detection

    Text recognition

    On-device text recognition

    Detecting text on a device

    Cloud-based text recognition

    Configuring the detector

    Summary

    A Snapchat-Like AR Filter on Android

    MobileNet models

    Building the dataset

    Retraining of images 

    Model conversion from GraphDef to TFLite

    Gender model

    Emotion model

    Comparison of MobileNet versions

    Building the Android application

    References

    Questions

    Summary

    Handwritten Digit Classifier Using Adversarial Learning

    Generative Adversarial Networks

    Generative versus discriminative algorithms

    Steps in GAN

    Understanding the MNIST database

    Building the TensorFlow model

    Training the neural network

    Building the Android application

    FreeHandView for writing

    Digit classifier

    Summary

    Face-Swapping with Your Friends Using OpenCV

    Understanding face-swapping

    Steps in face-swapping

    Facial key point detection

    Identifying the convex hull

    Delaunay triangulation and Voronoi diagrams

    Affine warp triangles

    Seamless cloning

    Building the Android application

    Building a native face-swapper library

    Android.mk

    Application.mk

    Applying face-swapping logic

    Building the application

    Summary

    References

    Questions

    Classifying Food Using Transfer Learning

    Transfer learning

    Approaches in transfer learning

    Training our own TensorFlow model 

    Installing TensorFlow

    Training the images

    Retraining with own images

    Training steps parameter

    Architecture

    Distortions

    Hyperparameters

    Running the training script

    Model conversion

    Building the iOS application

    Summary

    What's Next?

    What you have learned so far

    Where to start when developing an ML application

    IBM Watson services

    Microsoft Azure Cognitive Services

    Amazon ML

    Google Cloud ML

    Building your own model

    Limitations of building your own model

    Personalized user experience

    Better search results

    Targeting the right user

    Summary

    Further reading

    Other Books You May Enjoy

    Leave a review - let other readers know what you think

    Preface

    Machine learning is a growing technique that focuses on the development of computer programs that can be changed or modified when exposed to new data. It has made significant advances that have enabled practical applications of machine learning (ML) and, by extension, the overall field of Artificial Intelligence (AI).

    This book presents the implementation of seven practical, real-world projects that will teach you how to leverage TensorFlow Lite and Core ML to perform efficient machine learning. We will be learning about the recent advancements in TensorFlow and its extensions, such as TensorFlow Lite, to design intelligent apps that learn from complex/large datasets. We will delve into advancements such as deep learning by building apps using deep neural network architecture such as Convolutional Neural Networks (CNNs), recurrent neural networks (RNNs), transfer learning, and much more. 

    By the end of this book, you will not only have mastered all the concepts of and learned how to implement machine learning and deep learning, but you will also have learned how to solve the problems and challenges faced while building powerful apps on mobile using TensorFlow Lite and Core ML.

    Who this book is for

    Machine Learning Projects for Mobile Applications is for you if you are a data scientist, ML expert, deep learning, or AI enthusiast who fancies mastering ML and deep learning implementation with practical examples using TensorFlow and Keras. Basic knowledge of Python programming language would be an added advantage.

    What this book covers

    Chapter 1, Mobile Landscapes in Machine Learning, makes us familiar with the basic ideas behind TensorFlow Lite and Core ML.

    Chapter 2, CNN Based Age and Gender Identification Using Core ML, teaches us how to build an iOS application to detect the age, gender, and emotion of a person from a camera feed or from the user's photo gallery using the existing data models that were built for the same purpose.

    Chapter 3, Applying Neural Style Transfer on Photos, teaches us how to build a complete iOS and Android application in which image transformations are applied to our own images in a fashion similar to the Instagram app.

    Chapter 4, Deep Diving into the ML Kit with Firebase, explores the Google Firebase-based ML Kit platform for mobile applications.

    Chapter 5, A Snapchat-Like AR Filter on Android, takes us on a journey where we will build an AR filter that is used on applications such as Snapchat and Instagram using TensorFlow Lite.

    Chapter 6, Handwritten Digit Classifier Using Adversarial Learning, explains how to build an Android application that identifies handwritten digits. 

    Chapter 7, Face-Swapping with Your Friends Using OpenCV, takes a close look at building an application where a face in an image is replaced by another face.

    Chapter 8, Classifying Food Using Transfer Learning, explains how to classify food items using transfer learning. 

    Chapter 9, What's Next?, gives us a glimpse into all the applications built throughout the book and their relevance in the future.

    To get the most out of this book

    If you have prior knowledge of building mobile apps, that will help greatly. If not, it is advisable to learn the basics of Java or Kotlin for Android, or Swift for iOS. 

    If you have basic knowledge of Python, that will help you build your own data model, but Python skill is not mandatory. 

    The applications in the book are built using a MacBook Pro. Most of the command-line operations are shown with the assumption that you have a bash shell installed on your machine. They may not work in a Windows development environment.

    Download the code

    You can download the example code files for this book from your account at www.packt.com. If you purchased this book elsewhere, you can visit www.packt.com/support and register to have the files emailed directly to you.

    You can download the code files by following these steps:

    Log in or register at www.packt.com.

    Select the SUPPORT tab.

    Click on Code Downloads & Errata.

    Enter the name of the book in the Search box and follow the onscreen instructions.

    Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:

    WinRAR/7-Zip for Windows

    Zipeg/iZip/UnRarX for Mac

    7-Zip/PeaZip for Linux

    The code bundle for the book is also hosted on GitHub at https://github.com/PacktPublishing/Machine-Learning-Projects-for-Mobile-Applications. In case there's an update to the code, it will be updated on the existing GitHub repository.

    We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!

    Download the color images

    We also provide a PDF file that has color images of the screenshots/diagrams used in this book. You can download it here: https://www.packtpub.com/sites/default/files/downloads/9781788994590_ColorImages.pdf.

    Conventions used

    There are a number of text conventions

    Enjoying the preview?
    Page 1 of 1