Creating the Android app

We need to get the TensorFlow libraries for Android, create an Android app, configure it to use these libraries, and then invoke the TensorFlow model inside the app.

Although you can compile the TensorFlow libraries from scratch, it’s easier to use the prebuilt libraries.

Now use Android Studio to create an Android project with an empty activity.

Once the project is created, add the TF Libraries to the project's libs folder. You can get these libraries from the GitHub repository: https://github.com/PacktPublishing/Machine-Learning-for-Mobile/tree/master/tensorflow%20simple/TensorflowSample/app/libs.

Now your project's libs/ folder should look like this:

libs
|____arm64-v8a
| |____libtensorflow_inference.so
|____armeabi-v7a
| |____libtensorflow_inference.so
|____libandroid_tensorflow_inference_java.jar
|____x86
| |____libtensorflow_inference.so
|____x86_64
| |____libtensorflow_inference.so

You need to let your build system know where these libraries are located by putting the following lines inside of the Android block in app/build.gradle:

sourceSets { main { jniLibs.srcDirs = ['libs'] } }
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset