Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Port TensorFlow code to Android

I have written a script for sequence classification using TensorFlow in Python. I would like to port this code to Android. I have seen the example on the TensorFlow github page regarding Android but that is for images.

Is there any way to directly port my TensorFlow Python code on Android?

like image 279
Shoaib Ahmed Siddiqui Avatar asked Dec 27 '15 08:12

Shoaib Ahmed Siddiqui


People also ask

Can I use TensorFlow with Android?

TensorFlow Lite lets you run TensorFlow machine learning (ML) models in your Android apps. The TensorFlow Lite system provides prebuilt and customizable execution environments for running models on Android quickly and efficiently, including options for hardware acceleration.

Does TensorFlow support mobile phone?

TensorFlow Mobile is used for a mobile platform such as iOS and Android.


1 Answers

The typical way to do this is to build (and train) your model using Python, save the GraphDef proto to a file using tf.train.write_graph(), and then write an app using the JNI to call the C++ TensorFlow API (see a complete example here).

When you build your graph in Python, you should take note of the names of the tensors that will represent (i) the input data to be classified, and (ii) the predicted output values. Then you will be able to run a step by feeding a value for (i), and fetching the value for (ii).

One final concern is how to represent the model parameters in your exported graph. There are several ways to do this, including shipping a TensorFlow checkpoint (written by a tf.train.Saver) as part of your app, and running the restore ops to reload it. One method, which has been used in the released InceptionV3 model is to rewrite the graph so that the model parameters are replaced with "Const" nodes, and the model graph becomes self contained.

like image 101
mrry Avatar answered Sep 22 '22 14:09

mrry