วันอาทิตย์ที่ 10 กันยายน พ.ศ. 2560

Android Flower Images Classifier with TensorFlow Machine Learning

Android Flower Images Classifier with TensorFlow Machine Learning 

About TensorFlow Machine Learning Library
In this blog, we will learn how to install and run TensorFlow on Android, and will train a simple classifier to classify images of flowers. 
Daisy , Dandelion , Roses , Tulip , Sunflowers

Let's Started


1.Get Android TensorFlow Demo Code

Google’s open source TensorFlow project includes a wonderfully documented demo Android app.
https://github.com/tensorflow/tensorflow




The demo app is really four apps, but we’re going to focus on the “TF Classify” only.
TF Classify opens your camera, and classifies whatever objects you show it. The really mind blowing thing is that this works totally offline — you do not need an internet connection. I had a lot of fun with this.
It prints out the object classification along with a confidence level (1.000 for perfect confidence, 0.000 for zero confidence). When your object fills most of the image, it often does pretty well.

Need Android Studio install


2.Bazel : Building the Android TensorFlow Demo Code


NOTE: Bazel does not currently support building for Android on Windows. Full support for gradle/cmake builds is coming soon, but in the meantime we suggest that Windows users download the prebuilt binaries instead.
Install Bazel and Android Prerequisites
Bazel is the primary build system for TensorFlow. To build with Bazel, it and the Android NDK and SDK must be installed on your system.
  1. Install the latest version of Bazel as per the instructions on the Bazel website.
  2. The Android NDK is required to build the native (C/C++) TensorFlow code. The current recommended version is 12b, which may be found here.
  3. The Android SDK and build tools may be obtained here, or alternatively as part of Android Studio. Build tools API >= 23 is required to build the TF Android demo (though it will run on API >= 21 devices).
Edit WORKSPACE
The Android entries in <workspace_root>/WORKSPACE must be uncommented with the paths filled in appropriately depending on where you installed the NDK and SDK. Otherwise an error such as: "The external label '//external:android/sdk' is not bound to anything" will be reported.
Also edit the API levels for the SDK in WORKSPACE to the highest level you have installed in your SDK. This must be >= 23 (this is completely independent of the API level of the demo, which is defined in AndroidManifest.xml). The NDK API level may remain at 14.
Build
After editing your WORKSPACE file to update the SDK/NDK configuration, you may build the APK. Run this from your workspace root:
bazel build -c opt //tensorflow/examples/android:tensorflow_demo
Install
Make sure that adb debugging is enabled on your Android 5.0 (API 21) or later device, then after building use the following command from your workspace root to install the APK:
adb install -r bazel-bin/tensorflow/examples/android/tensorflow_demo.apk

3.Install TensorFlow on your machine.
https://www.tensorflow.org/install/

What is TensorFlow?

need install Python 2.7 or 3.3+ and pip install first. and basic understand of linux command.


We have install TensorFlow on Macbook Pro OSX EI Caption Versions 10.11.4 . It work fine.
and use with Python 2.7


4.Prepare the Training Images and Retrain Model
We have follow details in codelabs
https://codelabs.developers.google.com/codelabs/tensorflow-for-poets/




5.Using our Model in an Android App
Now let’s make a couple minor changes to the Android project to use our custom model.

First, copy your model and labels into the project’s assets folder. Mine were at tf_files/retrained_graph.pb and  tf_files/retrain_labels.txt.
Next, open up ClassifierActivity, which can be found in:
tensorflow/examples/android/src/org/tensorflow/demo/ClassifierActivity.java

You’ll want to update the constants at the top of the file to define the settings for our new model. It looks like this when you first open it:


Change it to:

Hit run to build the project and load the APK on your device, and you’ve got your flowers classifier!




The Results 



Here’s a video


Reference
TensorFlow Android Demo Code
https://androidcontrol.blogspot.com/2017/09/android-flower-images-classifier-tensorflow.html



My Website
email : info@softpowergroup.net  ,amphancm@gmail.com
Tel .+6681-6452400 ( Thailand )