Book Image

Intelligent Mobile Projects with TensorFlow

By : Jeff Tang
Book Image

Intelligent Mobile Projects with TensorFlow

By: Jeff Tang

Overview of this book

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.
Table of Contents (14 chapters)

Running the TensorFlow and Keras models on iOS

We won't bore you by repeating the project setup step - just follow what we did before to create a new Objective-C project named StockPrice that will use the manually built TensorFlow library (see the iOS section of Chapter 7, Recognizing Drawing with CNN and LSTM, if you need detailed info). Then add the two amzn_tf_frozen.pb and amzn_keras_frozen.pb model files to the project and you should have your StockPrice project in Xcode, as in Figure 8.3:

Figure 8.3 iOS app using the TensorFlow- and Keras-trained models in Xcode

In ViewController.mm, we'll first declare some variables and one constant:

unique_ptr<tensorflow::Session> tf_session;
UITextView *_tv;
UIButton *_btn;
NSMutableArray *_closeprices;
const int SEQ_LEN = 20;

Then create a button-tap handler to let the user choose either the TensorFlow or Keras model ...