Machine Learning Projects for Mobile Applications - Karthikeyan NG - E-Book

Machine Learning Projects for Mobile Applications E-Book

Karthikeyan NG

0,0
36,59 €

-100%
Sammeln Sie Punkte in unserem Gutscheinprogramm und kaufen Sie E-Books und Hörbücher mit bis zu 100% Rabatt.

Mehr erfahren.
Beschreibung

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.

Das E-Book können Sie in Legimi-Apps oder einer beliebigen App lesen, die das folgende Format unterstützen:

EPUB

Seitenzahl: 217

Veröffentlichungsjahr: 2018

Bewertungen
0,0
0
0
0
0
0
Mehr Informationen
Mehr Informationen
Legimi prüft nicht, ob Rezensionen von Nutzern stammen, die den betreffenden Titel tatsächlich gekauft oder gelesen/gehört haben. Wir entfernen aber gefälschte Rezensionen.



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 CastelinoContent Development Editor:Rhea HenriquesTechnical Editor: Sayli NikaljeCopy Editor: Safis EditingProject Coordinator: Manthan PatelProofreader: Safis EditingIndexer: Mariammal ChettiyarGraphics:Jisha ChirayilProduction 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 Narkhedehas 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.

Get in touch

Feedback from our readers is always welcome.

General feedback: If you have questions about any aspect of this book, mention the book title in the subject of your message and email us at [email protected].

Errata: Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you have found a mistake in this book, we would be grateful if you would report this to us. Please visit www.packt.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details.

Piracy: If you come across any illegal copies of our works in any form on the Internet, we would be grateful if you would provide us with the location address or website name. Please contact us at [email protected] with a link to the material.

If you are interested in becoming an author: If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, please visit authors.packtpub.com.

Reviews

Please leave a review. Once you have read and used this book, why not leave a review on the site that you purchased it from? Potential readers can then see and use your unbiased opinion to make purchase decisions, we at Packt can understand what you think about our products, and our authors can see your feedback on their book. Thank you!

For more information about Packt, please visit packt.com.

Mobile Landscapes in Machine Learning

Computers are improving by the day, and device form factors are changing tremendously. In the past, we would only see computers at offices, but now we see them on our home desks, on our laps, in our pockets, and on our wrists. The market is becoming increasingly varied as machines are being equipped with more and more intelligence.

Almost every adult currently carries a device around with them, and it is estimated that we look at our smartphones at least 50 times a day, whether there is a need to or not. These machines affect our daily decision-making processes. Devices are now equipped with applications such as Siri, Google Assistant, Alexa, or Cortana, features that are designed to mimic human intelligence. The ability to answer any query thrown at them presents these types of technology as master humans. On the backend, these systems improve using the collective intelligence acquired from all users. The more you interact with virtual assistants, the better are the results they give out.

Despite these advancements, how much closer are we to creating a human brain through a machine? We are in 2018 now. If science discovers a way to control the neurons of our brain, this may be possible in the near future. Machines that mimic the capabilities of a human are helping to solve complex textual, visual, and audio problems. They resemble the tasks carried out by a human brain on a daily basis—on average, the human brain makes approximately 35,000 decisions in a day. 

While we will be able to mimic the human brain in the future, it will come at a cost. We don't have a cheaper solution for it at the moment. The magnitude of power consumption of a human brain simulation program limits it in comparison to a human brain. The human brain consumes about 20 W of power, while a simulation program consumes about 1 MW of power or more. Neurons in the human brain operate at a speed of 200 Hz, while a typical microprocessor operates at a speed of 2 GHz, which is 10 million times more than that.

While we are still far from cloning a human brain, we can implement an algorithm that makes conscious decisions based on previous data as well as data from similar devices. This is where the subset of Artificial Intelligence (AI) comes in handy. With predefined algorithms that identify patterns from the complex data we have, these types of intelligence can then give us useful information. 

When the computer starts making decisions without being instructed explicitly every time, we achieve machine learning (ML) capability. ML is used everywhere right now, including through features such as identifying email spam, recommending the best product to buy on an e-commerce website, tagging your face automatically on a social media photograph, and so on. All of these are done using the patterns identified in historical data, and also through algorithms that reduce unnecessary noise from the data and produce quality output. When the data accumulates more and more, the computers can make better decisions.

Since we have wider access to mobile devices and the amount of time we spend on those devices is rapidly increasing, it makes sense to run ML models on the mobile phone itself. In the mobile phone market, Android and iOS platforms take the lead to cover the whole smartphone spectrum. We will explore how TensorFlow Lite and Core ML works on these mobile platforms.

The topics that will be covered in this chapter are as follows:

ML basics (with an example)

TensorFlow and Core ML basics

Machine learning basics

ML is a concept that describes the process of a set of generic algorithms analyzing your data, and providing you with interesting data without writing any specific codes for your problem. 

Alternatively, we can look at ML as a black box how cutting edge scientists are using it to do something crazy like detecting epilepsy or cancer disease, yet your simple email inbox is using it to filter spam every day. 

On a larger level, ML can be classified into the following two categories:

Supervised learning

Unsupervised learning

Unsupervised learning

In this case, you only have input data (x) and no corresponding output variables. The goal for unsupervised learning is to model the underlying structure or distribution in the data in order to learn more about it.

In unsupervised learning, you may not have any data in the beginning. Say for example on the same scenario discussed above in supervised learning, you have a basket full of fruits and you are asked to group them into similar groups. But you don't have any previous data or there are no training or labeling is done earlier. In that case, you need to understand the domain first because you have no idea whether the input is a fruit or not. In that case, you need to first understand all the characteristics of every input and then to try to match with every new input. May be at the final step you might have classified all the red color fruits into one baskets and the green color fruits into another basket. But not an accurate classification. This is called as unsupervised learning.