1 Star 0 Fork 0

Elliott / TensorFlowAndroidMNIST

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
README.md 2.18 KB
一键复制 编辑 原始数据 按行查看 历史
kosuke miyoshi 提交于 2016-09-26 22:31 . update link to TensorFlow r0.10

TensorFlowAndroidMNIST - Android MNIST demo with TensorFlow

This is a demo app for Android with Tensorflow to detect handwritten digits.

image

This Android demo is based on Tensorflow tutorial.

MNIST For ML Beginners https://www.tensorflow.org/versions/r0.10/tutorials/mnist/beginners/index.html

Deep MNIST for Experts https://www.tensorflow.org/versions/r0.10/tutorials/mnist/pros/index.html

How to train model.

Training scripts for neural network model are located at

https://github.com/miyosuda/TensorFlowAndroidMNIST/tree/master/trainer-script

To create model by yourself, install Tensorflow and run python scripts like

$ python beginner.py

or

$ python expert.py

and locate exported .pb file to assets dir.

To export training model, I added some modification to original tutorial scripts.

Now Tensorflow cannot export network graph and trained network weight Variable at the same time, so we need to create another graph to export and convert Variable into constants.

After training is finished, converted trained Variable to numpy ndarray.

_W = W.eval(sess)
_b = b.eval(sess)

and then convert them into constant and re-create graph for exporting.

W_2 = tf.constant(_W, name="constant_W")
b_2 = tf.constant(_b, name="constant_b")

And then use tf.train.write_graph to export graph with trained weights.

How to build JNI codes

Native .so files are already built in this project, but if you would like to build it by yourself, please install and setup NDK.

First download, extract and place Android NDK.

http://developer.android.com/intl/ja/ndk/downloads/index.html

And then update your PATH environment variable. For example,

export NDK_HOME="/Users/[your-username]/Development/android/android-ndk-r11b"
export PATH=$PATH:$NDK_HOME

And build .so file in jni-build dir.

$ cd jni-build
$ make

and copy .so file into app/src/main/jniLibs/armeabi-v7a/ with

$ make install

(Unlike original Android demo in Tensorflow, you don't need to install bazel to build this demo.

Tensorflow library files (.a files) and header files are extracted from original Tensorflow Android demo r0.10.

C++
1
https://gitee.com/ylzheng/TensorFlowAndroidMNIST.git
git@gitee.com:ylzheng/TensorFlowAndroidMNIST.git
ylzheng
TensorFlowAndroidMNIST
TensorFlowAndroidMNIST
master

搜索帮助