利用tensorflow-hub工具,在谷歌训练模型上进行迁移学习。
一、说明和文件
tensorflow代码仓库:https://github.com/tensorflow/tensorflow
hub代码仓库:https://github.com/tensorflow/hub
hub迁移学习官网介绍(需要梯子):https://www.tensorflow.org/hub/tutorials/image_retraining#visualizing_the_retraining_with_tensorboard
预训练模型说明:https://github.com/tensorflow/models/tree/master/research/slim
测试图片集下载(需要梯子):http://download.tensorflow.org/example_images/flower_photos.tgz
Inception V3在线(需要梯子):
https://tfhub.dev/google/inaturalist/inception_v3/feature_vector/1
Inception V3模型本地下载(需要梯子):
https://tfhub.dev/google/inaturalist/inception_v3/feature_vector/1?tf-hub-format=compressed
二、tensorflow-hub安装
1 | source activate py36 |
三、训练模型
1.下载py文件retrain.py
https://github.com/tensorflow/hub/blob/master/examples/image_retraining/retrain.py
2.最简单的方式训练
1 | #--image_dir指定待训练图片集路径 |
3.查看py脚本完整参数
1 | python ./retrain.py -h |
4.较完整参数实例
1 | #--image_dir 指定待训练图片集路径 |
5.运行关键画面:
1 | INFO:tensorflow:Looking for images in 'daisy' |
四、测试模型
1.下载测试py文件label_image.py
https://github.com/tensorflow/tensorflow/blob/master/tensorflow/examples/label_image/label_image.py
2.可将文件放到retrain.py同目录下
1 | #--graph pb文件路径 |
3.运行关键画面:
1 | ..... |