android工程如何使用tensorflow
来源:互联网 发布:aframe.js下载 编辑:程序博客网 时间:2024/05/22 23:04
參考工程:https://github.com/miyosuda/TensorFlowAndroidMNIST
1.在python中訓練完模型後,使用
tf.train.write_graph(graph_def, './tmp/beginner-export', 'beginner-graph.pb', as_text=False)存儲模型。
2.在java中使用c 調用tensorflow的C接口 ,獲取訓練好的圖模型。
3.c調用tensorflow的c接口,識別。
TensorFlowAndroidMNIST - Android MNIST demo with TensorFlow
This is a demo app for Android with Tensorflow to detect handwritten digits.
This Android demo is based on Tensorflow tutorial.
MNIST For ML Beginnershttps://www.tensorflow.org/versions/r0.10/tutorials/mnist/beginners/index.html
Deep MNIST for Expertshttps://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 tobuild 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.
- android工程如何使用tensorflow
- tensorflow: 如何使用矩阵
- 如何使用tensorflow.layers.con2d_transpose
- 基于 eclipse 的 android 工程如何使用 jar 文件
- 如何使用命令行编译运行cocos2d-x的android工程
- 基于 eclipse 的 android 工程如何使用 jar 文件
- 如何使用GitHub进行团队Android工程的开发
- Android Studio 如何将子工程的APK输出到到主工程中被使用
- 在Android上使用Tensorflow
- 在Android上使用Tensorflow
- 【Tensorflow】Anaconda中激活tensorflow后如何使用
- 第三课:把tensorflow,模型和测试数据导入Android工程
- 第三课:把tensorflow,模型和测试数据导入Android工程
- Android如何引用其他工程
- Android如何引用其他工程
- android如何引用其他工程
- ****Android如何引用其他工程
- eclipse如何导入android工程
- 图邻接表有向表代码简洁实现
- SourceTree初学
- Android7.0 Messaging源码分析(0) - 启动篇
- 01UI-day4-151229
- NOIP2016考前总结
- android工程如何使用tensorflow
- 数据结构与算法简介
- Java设计模式17——模板方法模式
- Java性能调优-JPS、jmap、jconsole等
- tomcat服务器https配置及证书生成(笔记)
- OpenGL缓冲区对象之EBO
- Java 异步回调
- uboot的编译及连接过程
- webpack工作流程分析