Android tensorflow图片识别demo
2018-01-15 13:38
471 查看
1.Install Tensorflow,
if installed,upgrade to most recent stable branch with pip install --upgrade tensorflow
the model url is https://github.com/tensorflow/tensorflow/tree/master/tensorflow/examples/image_retraining
2.mkdir tensorlfowdemo cd [b]tensorlfowdemo [/b]
git clone https://github.com/googlecodelabs/tensorflow-for-poets-2
cd tensorflow-for-poets-2
3.Download the training images
curl http://download.tensorflow.org/example_images/flower_photos.tgz | tar xz -C tf_files
4.(Re) training the network
Configure your MobileNet
The retain script can retain either Inception V3 model or a MobileNet. 设置环境变量
IMAGE_SIZE=224 ARCHITECTURE="mobilenet_1.0_${IMAGE_SIZE}"(选择模型是
inception_v3还是mobilenet_v1_1.0)
Start TensorBoard
launch tensorboard in the background
tensorboard --logdir tf_files/trainning_summaries &
this command will fail with the following error if you already have a tensorboard process running
ERROR:tensorflow:tensorBoard attempted to bind to port 6006,but it was already in use,you can kill all existing TensorBoard instances with:
pkill -f "tensorboard"
if we want to see graph in tensorboard,we should mkdir tf_files/trainning_summaries and
python -m scripts.graph_pb2tb tf_files/training_summaries/retrained tf_files/retrained_graph.pb
see python help in command:python -m scripts.retrain -h
Run the training
python -m scripts.retrain --bottleneck_dir=tf_files/bottlenecks --how_many_training_steps=500 --model_dir=tf_files/models/ --summaries_dirs=tf_files/training_summaries/"${ARCHITECTURE}" --output_graph=tf_files/retrained_graph.pb
--output_labels=tf_files/retrained_labels.txt --architecture="$ARCHITECTURE" --image_dir=tf_files/flower_photos/
if you are using Docker and the above command fails reporting ERRO[xxx] error getting events from daemon:EOF increase your Docker cpu allocation to 4 or more
bottlenecks is an informal term we often use for the layer just before the final output layer that actually does the classification.
5.Using the Retained Model
in android we use tf_files/retrained_graph.pb and tf_files/retrained_labels.txt in assets
The codelab repo also contrains a copy of tensorflow's label_image.py example, python -m scripts.label_image -h
(检验模型是否预测准确,执行如下命令)
python -m scripts.label_image --graph=tf_files/retrained_graph.pb --image=tf_files/flower_photos/daisy/21652746_cc379e0eea_m.jpg
if you want to optimized the model .pb ,then do it
python -m tensorflow.python.tools.optimize_for_inference --input=tf_files/retrained_graph.pb --output=tf_files/optimized_graph.pb --input_names="input" --output_names="final_result"
******************************************************************************************************************************************************************************************************************
6.Training on Your Own Categories
In theory,all you need to do is run the tool,specifying a particular set of sub-folders.Each sub-folder is named after one of your categories and contains only images from that category.
PS
in source code ,we can train in following command
bazel build tensorflow/examples/image_retraining:retrain
If you have a machine which suports the AVX instruction set,you can improve the running speed of the retraining by building for that architecture. bazel build --config opt tensorflow/examples/image_retraining:retrain
The retrainer can then be run like this
bazel -bin/tensorflow/examples/image_retraining:retrain --image_dir ~/flower_photos
参考 https://codelabs.developers.google.com/codelabs/tensorflow-for-poets/index.html#0
if installed,upgrade to most recent stable branch with pip install --upgrade tensorflow
the model url is https://github.com/tensorflow/tensorflow/tree/master/tensorflow/examples/image_retraining
2.mkdir tensorlfowdemo cd [b]tensorlfowdemo [/b]
git clone https://github.com/googlecodelabs/tensorflow-for-poets-2
cd tensorflow-for-poets-2
3.Download the training images
curl http://download.tensorflow.org/example_images/flower_photos.tgz | tar xz -C tf_files
4.(Re) training the network
Configure your MobileNet
The retain script can retain either Inception V3 model or a MobileNet. 设置环境变量
IMAGE_SIZE=224 ARCHITECTURE="mobilenet_1.0_${IMAGE_SIZE}"(选择模型是
inception_v3还是mobilenet_v1_1.0)
Start TensorBoard
launch tensorboard in the background
tensorboard --logdir tf_files/trainning_summaries &
this command will fail with the following error if you already have a tensorboard process running
ERROR:tensorflow:tensorBoard attempted to bind to port 6006,but it was already in use,you can kill all existing TensorBoard instances with:
pkill -f "tensorboard"
if we want to see graph in tensorboard,we should mkdir tf_files/trainning_summaries and
python -m scripts.graph_pb2tb tf_files/training_summaries/retrained tf_files/retrained_graph.pb
see python help in command:python -m scripts.retrain -h
Run the training
python -m scripts.retrain --bottleneck_dir=tf_files/bottlenecks --how_many_training_steps=500 --model_dir=tf_files/models/ --summaries_dirs=tf_files/training_summaries/"${ARCHITECTURE}" --output_graph=tf_files/retrained_graph.pb
--output_labels=tf_files/retrained_labels.txt --architecture="$ARCHITECTURE" --image_dir=tf_files/flower_photos/
if you are using Docker and the above command fails reporting ERRO[xxx] error getting events from daemon:EOF increase your Docker cpu allocation to 4 or more
bottlenecks is an informal term we often use for the layer just before the final output layer that actually does the classification.
5.Using the Retained Model
in android we use tf_files/retrained_graph.pb and tf_files/retrained_labels.txt in assets
The codelab repo also contrains a copy of tensorflow's label_image.py example, python -m scripts.label_image -h
(检验模型是否预测准确,执行如下命令)
python -m scripts.label_image --graph=tf_files/retrained_graph.pb --image=tf_files/flower_photos/daisy/21652746_cc379e0eea_m.jpg
if you want to optimized the model .pb ,then do it
python -m tensorflow.python.tools.optimize_for_inference --input=tf_files/retrained_graph.pb --output=tf_files/optimized_graph.pb --input_names="input" --output_names="final_result"
******************************************************************************************************************************************************************************************************************
6.Training on Your Own Categories
In theory,all you need to do is run the tool,specifying a particular set of sub-folders.Each sub-folder is named after one of your categories and contains only images from that category.
PS
in source code ,we can train in following command
bazel build tensorflow/examples/image_retraining:retrain
If you have a machine which suports the AVX instruction set,you can improve the running speed of the retraining by building for that architecture. bazel build --config opt tensorflow/examples/image_retraining:retrain
The retrainer can then be run like this
bazel -bin/tensorflow/examples/image_retraining:retrain --image_dir ~/flower_photos
参考 https://codelabs.developers.google.com/codelabs/tensorflow-for-poets/index.html#0
相关文章推荐
- Android静态图片人脸识别的完整demo(附完整源码)
- Android人脸识别Demo竖屏YUV方向调整和图片保存(分享)
- Android+TensorFlow+CNN+MNIST 手写数字识别实现
- TensorFlow RNN MNIST字符识别Demo快速了解TF RNN核心框架
- Android人脸识别Demo竖屏YUV方向调整和图片保存
- Android+TensorFlow+CNN+MNIST实现手写数字识别
- Tensorflow Lite Android Demo App
- Ubuntu 使用 Android Studio 编译 TensorFlow android demo
- TensorFlow on Android:物体识别
- Android静态图片人脸识别的完整demo(附完整源码)
- Android静态图片人脸识别的完整demo(附完整源码)
- 第一时间测试TensorflowLite Android Demo,性能平均200ms
- Android+TensorFlow+CNN+MNIST 手写数字识别实现
- Ubuntu 使用 Android Studio 编译 TensorFlow android demo
- TensorFlow on Android:物体识别
- Android异步从网络下载图片并且缓存图片到本地的demo
- TensorFlow/对抗网络DCGAN生成图片
- 机器学习: TensorFlow with MLP 笑脸识别
- 【Android游戏开发十六】Android Gesture之【触摸屏手势识别】操作!利用触摸屏手势实现一个简单切换图片的功能!
- Android中使用MediaCodec硬件解码,高效率得到YUV格式帧,快速保存JPEG图片(不使用OpenGL)(附Demo)