Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
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
€22.99 €32.99
Paperback
€41.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with a Packt Subscription?

Free for first 7 days. €18.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing
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 : 9781788834544
Vendor :
Google
Category :
Languages :
Tools :

What do you get with a Packt Subscription?

Free for first 7 days. €18.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing

Product Details

Publication date : May 22, 2018
Length: 404 pages
Edition : 1st
Language : English
ISBN-13 : 9781788834544
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

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

What is included in a Packt subscription? Chevron down icon Chevron up icon

A subscription provides you with full access to view all Packt and licnesed content online, this includes exclusive access to Early Access titles. Depending on the tier chosen you can also earn credits and discounts to use for owning content

How can I cancel my subscription? Chevron down icon Chevron up icon

To cancel your subscription with us simply go to the account page - found in the top right of the page or at https://subscription.packtpub.com/my-account/subscription - From here you will see the ‘cancel subscription’ button in the grey box with your subscription information in.

What are credits? Chevron down icon Chevron up icon

Credits can be earned from reading 40 section of any title within the payment cycle - a month starting from the day of subscription payment. You also earn a Credit every month if you subscribe to our annual or 18 month plans. Credits can be used to buy books DRM free, the same way that you would pay for a book. Your credits can be found in the subscription homepage - subscription.packtpub.com - clicking on ‘the my’ library dropdown and selecting ‘credits’.

What happens if an Early Access Course is cancelled? Chevron down icon Chevron up icon

Projects are rarely cancelled, but sometimes it's unavoidable. If an Early Access course is cancelled or excessively delayed, you can exchange your purchase for another course. For further details, please contact us here.

Where can I send feedback about an Early Access title? Chevron down icon Chevron up icon

If you have any feedback about the product you're reading, or Early Access in general, then please fill out a contact form here and we'll make sure the feedback gets to the right team. 

Can I download the code files for Early Access titles? Chevron down icon Chevron up icon

We try to ensure that all books in Early Access have code available to use, download, and fork on GitHub. This helps us be more agile in the development of the book, and helps keep the often changing code base of new versions and new technologies as up to date as possible. Unfortunately, however, there will be rare cases when it is not possible for us to have downloadable code samples available until publication.

When we publish the book, the code files will also be available to download from the Packt website.

How accurate is the publication date? Chevron down icon Chevron up icon

The publication date is as accurate as we can be at any point in the project. Unfortunately, delays can happen. Often those delays are out of our control, such as changes to the technology code base or delays in the tech release. We do our best to give you an accurate estimate of the publication date at any given time, and as more chapters are delivered, the more accurate the delivery date will become.

How will I know when new chapters are ready? Chevron down icon Chevron up icon

We'll let you know every time there has been an update to a course that you've bought in Early Access. You'll get an email to let you know there has been a new chapter, or a change to a previous chapter. The new chapters are automatically added to your account, so you can also check back there any time you're ready and download or read them online.

I am a Packt subscriber, do I get Early Access? Chevron down icon Chevron up icon

Yes, all Early Access content is fully available through your subscription. You will need to have a paid for or active trial subscription in order to access all titles.

How is Early Access delivered? Chevron down icon Chevron up icon

Early Access is currently only available as a PDF or through our online reader. As we make changes or add new chapters, the files in your Packt account will be updated so you can download them again or view them online immediately.

How do I buy Early Access content? Chevron down icon Chevron up icon

Early Access is a way of us getting our content to you quicker, but the method of buying the Early Access course is still the same. Just find the course you want to buy, go through the check-out steps, and you’ll get a confirmation email from us with information and a link to the relevant Early Access courses.

What is Early Access? Chevron down icon Chevron up icon

Keeping up to date with the latest technology is difficult; new versions, new frameworks, new techniques. This feature gives you a head-start to our content, as it's being created. With Early Access you'll receive each chapter as it's written, and get regular updates throughout the product's development, as well as the final course as soon as it's ready.We created Early Access as a means of giving you the information you need, as soon as it's available. As we go through the process of developing a course, 99% of it can be ready but we can't publish until that last 1% falls in to place. Early Access helps to unlock the potential of our content early, to help you start your learning when you need it most. You not only get access to every chapter as it's delivered, edited, and updated, but you'll also get the finalized, DRM-free product to download in any format you want when it's published. As a member of Packt, you'll also be eligible for our exclusive offers, including a free course every day, and discounts on new and popular titles.