Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Intelligent Mobile Projects with TensorFlow
Intelligent Mobile Projects with TensorFlow

Intelligent Mobile Projects with TensorFlow: Build 10+ Artificial Intelligence apps using TensorFlow Mobile and Lite for iOS, Android, and Raspberry Pi

eBook
€8.99 €32.99
Paperback
€41.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Table of content icon View table of contents Preview book icon Preview Book

Intelligent Mobile Projects with TensorFlow

Classifying Images with Transfer Learning

The sample TensorFlow iOS apps, simple and camera, and the Android app TF Classify, described in the previous chapter all use the Inception v1 model, a pretrained image classification deep neural network model made publicly available by Google. The model is trained for ImageNet (http://image-net.org), one of the largest and best-known image databases with over 10 million images annotated for object classes. The Inception model can be used to classify an image into one of the 1,000 classes, listed at http://image-net.org/challenges/LSVRC/2014/browse-synsets. Those 1,000 object classes include quite a few dog breeds, among many kinds of objects. But the accuracy for recognizing dog breeds is not that high, around 70%, because the model is trained for recognizing a large number of objects, instead of a specific set of objects such as dog...

Transfer learning – what and why

We human beings don't learn new things from scratch. Instead, we take advantage of what we have learned as much as possible, consciously or not. Transfer learning in AI attempts to do the same thing—it's a technique that takes a normally small piece of a big trained model and reuses it in a new model for a related task, without the need to access the large training data and computing resources to train the original model. Overall, transfer learning is still an open problem in AI, since in many situations, what takes human beings only a few examples of trial-and-errors before learning to grasp something new would take AI a lot more time to train and learn. But in the field of image recognition, transfer learning has proven to be very effective.

Modern deep learning models for image recognition are typically deep neural networks...

Retraining using the Inception v3 model

In the TensorFlow source that we set up in the previous chapter, there's a Python script, tensorflow/examples/image_retraining/retrain.py, that you can use to retrain the Inception v3 or MobileNet models. Before we run the script to retrain the Inception v3 model for our dog breed recognition, we need to first download the Stanford Dogs Dataset (http://vision.stanford.edu/aditya86/ImageNetDogs), which contains images of 120 dog breeds (you only need to download the Images in the link, not the Annotations).

Untar the downloaded dog images.tar file in ~/Downloads, and you should see a list of folders in ~/Downloads/Images, as shown in the following screenshot. Each folder corresponds to one dog breed and contains about 150 images (you don't need to supply explicit labels for images as the folder names are used to label the images...

Retraining using MobileNet models

The stripped and quantized model generated in the previous section is still over 20 MB in size. This is because the pre-built Inception v3 model used for retraining is a large-scale deep learning model, with over 25 million parameters, and Inception v3 was not created with a mobile-first goal.

In June 2017, Google released MobileNets v1, a total of 16 mobile-first deep learning models for TensorFlow. These models are only a few MB in size, with 0.47 million to 4.24 million parameters, still achieving decent accuracy (just a bit lower than Inception v3). See its README for more information: https://github.com/tensorflow/models/blob/master/research/slim/nets/mobilenet_v1.md.

The retrain.py script discussed in the previous section also supports retraining based on MobileNet models. Simply run a command like the following:

python tensorflow/examples...

Using the retrained models in the sample iOS app

The iOS simple example we see in Chapter 1, Getting Started with Mobile TensorFlow, uses the Inception v1 model. To make the app use our retrained Inception v3 model and MobileNet model to do better dog breed recognition, we need to make a few changes to the app. Let's first see what it takes to use the retrained quantized_stripped_dogs_retrained.pb in the iOS simple app:

  1. Double-click the tf_simple_example.xcworkspace file in tensorflow/examples/ios/simple to open the app in Xcode
  2. Drag the quantized_stripped_dogs_retrained.pb model file, the dog_retrained_labels.txt label file, and the lab1.jpg image file we used to test the label_image script, and drop to the project's data folder, making sure both Copy items if needed and Add to targets are checked, as shown in the following screenshot:
Figure 2.5 Adding the retrained...

Using the retrained models in the sample Android app

To use our retrained Inception v3 model and MobileNet model in Android's TF Classify app is also pretty straightforward. Follow the steps here to test both retrained models:

  1. Open the sample TensorFlow Android app, located in tensorflow/examples/android, using Android Studio.
  2. Drag and drop two retrained models, quantized_stripped_dogs_retrained .pb and dog_retrained_mobilenet10_224.pb as well as the label file, dog_retrained_labels.txt to the assets folder of the android app.
  3. Open the file ClassifierActivity.java, to use the Inception v3 retrained model, and replace the following code:
private static final int INPUT_SIZE = 224; 
private static final int IMAGE_MEAN = 117; 
private static final float IMAGE_STD = 1; 
private static final String INPUT_NAME = "input"; 
private static final String OUTPUT_NAME = &quot...

Adding TensorFlow to your own iOS app

In the earlier version of TensorFlow, adding TensorFlow to your own app was very tedious, requiring the use of the manual build process of TensorFlow and other manual settings. In TensorFlow 1.4, the process is pretty straightforward, but still, detailed steps are not well documented in the TensorFlow website. One other thing that's missing is the lack of documentation on how to use TensorFlow in your Swift-based iOS app; the sample TensorFlow iOS apps are all in Objective-C, calling TensorFlow's C++ APIs. Let's see how we can do better.

Adding TensorFlow to your Objective-C iOS app

First, follow these steps to add TensorFlow with the image classification feature to your...

Adding TensorFlow to your own Android app

It turns out that adding TensorFlow to your own Android app is easier than iOS. Let's jump right to the steps:

  1. If you have an existing Android app, skip this. Otherwise, in Android Studio, select File | New | New Project... and accept all the defaults before clicking Finish.
  2. Open the build.gradle (Module: app) file, and add compile 'org.tensorflow:tensorflow-android:+' inside and at the end of dependencies {...};.
  3. Build the gradle file and you'll see libtensorflow_inference.so, the TensorFlow native library that Java code talks to, inside the subfolders of the location app/build/intermediates/transforms/mergeJniLibs/debug/0/lib of your app directory.
  4. If this is a new project, you can create the assets folder by first switching to Packages, then by right-mouse clicking the app and selecting New | Folder | Assets Folder...

Summary

In this chapter, we first gave a quick overview on what is transfer learning and why we can and should use it to retrain pretrained deep learning image classification models. Then we presented detailed information on how to retrain an Inception v3-based model and a MobileNet model so we can better understand and recognize our best friends. After that, we first showed how to use the retrained models in the TensorFlow sample iOS and Android apps, then gave step-by-step tutorials on how to add TensorFlow to your own iOS app, both Objective-C and Swift-based, and your own Android app.

Now that we have our best friends, with a few nice and clean tricks, covered, we know there are a lot of other guys out there, good or bad. In the next chapter, we'll learn how to be smarter, how to recognize all the interesting objects in a picture, and locate them, on your smart phone...

Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • Build TensorFlow-powered AI applications for mobile and embedded devices 
  • Learn modern AI topics such as computer vision, NLP, and deep reinforcement learning
  • Get practical insights and exclusive working code not available in the TensorFlow documentation

Description

As a developer, you always need to keep an eye out and be ready for what will be trending soon, while also focusing on what's trending currently. So, what's better than learning about the integration of the best of both worlds, the present and the future? Artificial Intelligence (AI) is widely regarded as the next big thing after mobile, and Google's TensorFlow is the leading open source machine learning framework, the hottest branch of AI. This book covers more than 10 complete iOS, Android, and Raspberry Pi apps powered by TensorFlow and built from scratch, running all kinds of cool TensorFlow models offline on-device: from computer vision, speech and language processing to generative adversarial networks and AlphaZero-like deep reinforcement learning. You’ll learn how to use or retrain existing TensorFlow models, build your own models, and develop intelligent mobile apps running those TensorFlow models. You'll learn how to quickly build such apps with step-by-step tutorials and how to avoid many pitfalls in the process with lots of hard-earned troubleshooting tips.

Who is this book for?

If you're an iOS/Android developer interested in building and retraining others' TensorFlow models and running them in your mobile apps, or if you're a TensorFlow developer and want to run your new and amazing TensorFlow models on mobile devices, this book is for you. You'll also benefit from this book if you're interested in TensorFlow Lite, Core ML, or TensorFlow on Raspberry Pi.

What you will learn

  • • Classify images with transfer learning
  • • Detect objects and their locations
  • • Transform pictures with amazing art styles
  • • Understand simple speech commands
  • • Describe images in natural language
  • • Recognize drawing with Convolutional Neural Network and Long Short-Term Memory
  • • Predict stock price with Recurrent Neural Network in TensorFlow and Keras
  • • Generate and enhance images with generative adversarial networks
  • • Build AlphaZero-like mobile game app in TensorFlow and Keras
  • • Use TensorFlow Lite and Core ML on mobile
  • • Develop TensorFlow apps on Raspberry Pi that can move, see, listen, speak, and learn

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : May 22, 2018
Length: 404 pages
Edition : 1st
Language : English
ISBN-13 : 9781788628808
Vendor :
Google
Category :
Languages :
Tools :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : May 22, 2018
Length: 404 pages
Edition : 1st
Language : English
ISBN-13 : 9781788628808
Vendor :
Google
Category :
Languages :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
€18.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
€189.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts
€264.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 120.97
Reinforcement Learning with TensorFlow
€41.99
Intelligent Mobile Projects with TensorFlow
€41.99
Artificial Intelligence for Big Data
€36.99
Total 120.97 Stars icon
Banner background image

Table of Contents

13 Chapters
Getting Started with Mobile TensorFlow Chevron down icon Chevron up icon
Classifying Images with Transfer Learning Chevron down icon Chevron up icon
Detecting Objects and Their Locations Chevron down icon Chevron up icon
Transforming Pictures with Amazing Art Styles Chevron down icon Chevron up icon
Understanding Simple Speech Commands Chevron down icon Chevron up icon
Describing Images in Natural Language Chevron down icon Chevron up icon
Recognizing Drawing with CNN and LSTM Chevron down icon Chevron up icon
Predicting Stock Price with RNN Chevron down icon Chevron up icon
Generating and Enhancing Images with GAN Chevron down icon Chevron up icon
Building an AlphaZero-like Mobile Game App Chevron down icon Chevron up icon
Using TensorFlow Lite and Core ML on Mobile Chevron down icon Chevron up icon
Developing TensorFlow Apps on Raspberry Pi Chevron down icon Chevron up icon
Other Books You May Enjoy Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Full star icon Full star icon Full star icon Full star icon 5
(4 Ratings)
5 star 100%
4 star 0%
3 star 0%
2 star 0%
1 star 0%
triston Jul 13, 2018
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I am very delighted that there is so much useful and practical information in this book. From convolution neural networks to recurrent neural networks, from where to find the resources to how to put it into your smart apps, it is one of best books in the market to help you to build intelligent mobile projects. It also a very nice tutorial book for machine learning, especially machine learning through Tenorflow, even though you have no interest in developing apps or projects on mobile devices.
Amazon Verified review Amazon
gary d. smith Jul 01, 2018
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I was looking for an entry level book that included at least some information on the use of the Raspberry PI with TensorFlow, but not one that was dumbed down too much. This fits my needs perfectly.. I read through the whole book and am now working through my first example and so far going well. I like his writing style which helps me a lot in understanding. This is not a 15 minute cookbook, but a well thought out and well written textbook. so be prepared to put some effort into it. I really like it.
Amazon Verified review Amazon
Rui Jul 15, 2018
Full star icon Full star icon Full star icon Full star icon Full star icon 5
As an iOS developer with little experience in machine learning, this book is an eye-opener for the many aspects that iOS and ML can be combined. I also found that the examples were easy to follow and inspirational for future projects.
Amazon Verified review Amazon
Ignacio Arias Oct 30, 2018
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Great author!
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.