How to run tensorflow reasoning on Android things, such as classifying images?

Does Android things support tensorflow? Can tensorflow Android sample be ported to Android things to run? If so, what is the easiest way?

resolvent:

Short answer: Yes, you can indeed run tensorflow on embedded devices running Android things (such as raspberry PI 3). We have ported the tensorflow image classification application to Android things. Available: https://github.com/androidthings/sample-tensorflow-imageclassifier.

Long answer: to run tensorflow, you first need to build a model diagram and train for a large input data set. After completion, you can reason according to the trained model to make wise decisions. The first part of the training takes up a lot of resources, usually completed in advance, while the reasoning part is relatively light. This is the inference part, Migrated to run on devices running Android things

The following summarizes what needs to be done when integrating tensorflow into the Android things project:

>First, add tensorflow Android inference library file to your project: tensorflow-android-inference-alpha-debug.aar > next, add a dependency in the build.gradle file of the application, as follows: compile (Name: 'tensorflow-android-inference-alpha-debug', ext: 'AAR')

To utilize tensorflow Android inference library, instantiate the org.tensorflow.contrib.android.tensorflow influenceinterface instance to expose the following methods:

>Initializetensorflow: initialize tensorflow object using model diagram as input > fillnodeflow: copy input data into tensorflow input array > runinference: run inference and save results in tensorflow output array > readnodeflow: read from tensorflow output array and save to your own array

Check the implementation in tensorflowimageclassifier.java of the image classifier sample to understand how to pass input to tensorflow, run reasoning and extract output labels from tensorflow. For example, in our image classification example, when displaying the image of a dog, our application can detect which kind of dog

The model graph in the sample is built using Google perception V3 tensorflow model, and its training set contains 1.2 million images from Imagenet. If you want to build your own model graph, please ensure that the model file, label file and input / output name are updated accordingly in the classifier implementation

In short, the method of using tensorflow Android influence library as gradle dependency outlined above provides a fast and easy way to add tensorflow core functions to any Android project, even complex projects with native code and requiring NDK integration (such as the tensorflow Android samples) This method can also extend the host platform to the host platform that does not fully support bazel, such as windows

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>