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

更多相关文章

  1. Using your own SQLite database in Android(安卓)applications
  2. Android(安卓)仿小米优品单行输入Dialog
  3. CentOS 安装 Android
  4. android:shape
  5. CentOS 安装 Android
  6. android之activity间传输数据
  7. Android(安卓)带固定图片的EditText
  8. Android(安卓)Studio编译失败:java.util.concurrent.ExecutionExc
  9. android 代码设置间距

随机推荐

  1. Android SDK官方下载地址及在线SDK网址
  2. 判断用户使用的是 Android 手机还是平板
  3. android keyboard keycode
  4. 企业级Android Application Activity管理
  5. android 使用vcard示例
  6. Android类型转换 积累
  7. android studio详细的编译错误提示
  8. Android检测版本更新(读取apk配置文件中的
  9. Android软键盘调用及隐藏,以及获得点击软
  10. Android Intent多种传值方式