Android tensorflow图片识别demo

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 tensorlfowdemo 

   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

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值