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)

Using the model in Android to play Connect 4

Not surprisingly, we don't need to use the custom Android library as we did in Chapter 7, Recognizing Drawing with CNN and LSTM, to load the model. Simply create a new Android Studio app with the name AlphaZero, copy the alphazero19.pb model file to the newly created assets folder, and add the compile 'org.tensorflow:tensorflow-android:+' line to the app's build.gradle file as we did before.

We'll first create a new class, BoardView, that extends View and is responsible for drawing the game board and the pieces AI and the user make:

public class BoardView extends View {
private Path mPathBoard, mPathAIPieces, mPathHumanPieces;
private Paint mPaint, mCanvasPaint;
private Canvas mCanvas;
private Bitmap mBitmap;
private MainActivity mActivity;

private static final float MARGINX = 20.0f;
private...