Ubuntu16.04 使用TensorFlow Hub重新划分图像分类器

11 篇文章 0 订阅
10 篇文章 0 订阅

1. 安装Tensorflow Hub

pip install "tensorflow>=1.7.0"
pip install tensorflow-hub

2. 获取花卉照片集

curl -LO http://download.tensorflow.org/example_images/flower_photos.tgz
tar xzf flower_photos.tgz

3. 下载训练代码

mkdir retrain
cd retrain/
curl -LO https://github.com/tensorflow/hub/raw/master/examples/image_retraining/retrain.py

4. 翻墙(不然训练时下载预先训练的模型会失败)

curl -LO https://raw.githubusercontent.com/getlantern/lantern-binaries/master/lantern-installer-64-bit.deb
dpkg -i lantern-installer-64-bit.deb
lantern

5. 训练

python retrain.py --image_dir ../flower_photos

注: 模型文件:/tmp/output_graph.pb, 标签文件文件:/tmp/output_labels.

6. 测试

git clone https://github.com/tensorflow/tensorflow
cd tensorflow
bazel build tensorflow/examples/label_image:label_image
bazel-bin/tensorflow/examples/label_image/label_image \
                --image=/test.jpg \
                --graph=/tmp/output_graph.pb \
                --labels=/tmp/output_labels.txt \
                --input_layer="Placeholder" \
                --output_layer="final_result"

输出结果:

​​​​​​​daisy (0): 0.86599
sunflowers (3): 0.131518
roses (2): 0.00105852
dandelion (1): 0.000859526
tulips (4): 0.000574312

注:  相看相关参数

bazel-bin/tensorflow/tools/graph_transforms/summarize_graph --in_graph=/tmp/output_graph.pb

7. 使用TensorBoard可视化再培训(可选)

tensorboard --logdir /tmp/retrain_logs

注:训练开始后执行以上命令,并在浏览器打开localhost:6006

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值