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 breeds.

What if we want to improve the accuracy and build a mobile app on our smart phone that uses the improved model so when we walk around and see an interesting dog, we can use the app to tell us what kind of dog it is.

In this chapter, we'll first discuss why transfer learning, or retraining pretrained deep learning models for such an image classification task, is the most cost-effective way to accomplish the task. Then we'll show you what it takes to retrain some of the best image classification models with a good dog dataset, and how to deploy and run the retrained models in the sample iOS and Android apps we covered in Chapter 1, Getting Started with Mobile TensorFlow. Also, we'll cover in step-by-step instructions how to add TensorFlow to your Objective-C or Swift-based iOS and Android apps.

In summary, we're going to cover the following topics in this chapter:

  • Transfer learning – what and why
  • Retraining using the Inception v3 model
  • Retraining using MobileNet models
  • Using the retrained models in the sample iOS app
  • Using the retrained models in the sample Android app
  • Adding TensorFlow to your own iOS app
  • Adding TensorFlow to your own Android app