本文在谷歌2015_CVPR Inception v3模型的基础上,结合花朵识别的具体问题重新训练该模型,以获取自己需要的tensorflow模型。

重新训练Inception v3实质是在原有模型输出层后,新加了一个输出层作为最终的输出层,我们只训练这个新加的输出层。这里使用了迁移学习的概念。

Transfer learning, which means we are starting with a model that has been already trained on another problem. We will then be retraining it on a similar problem. Deep learning from scratch can take days, but transfer learning can be done in short order.

准备

本节主要给出了训练tensorflow模型的一些前提条件。

硬件环境

  • Ubuntu 16.04

安装tensorflow

  • 参考tensorflow Github进行安装。

安装git

$ sudo apt-get update
$ sudo apt-get install git

准备训练样本

$ cd ~
$ mkdir tf_files
$ cd tf_files
$ curl -O http://download.tensorflow.org/example_images/flower_photos.tgz
$ tar xzf flower_photos.tgz
$ ls flower_photos

flower_photos.tgz有218MB。

[可选操作]

$ cd ~/tf_files
$ ls flower_photos/roses | wc -l
$ rm flower_photos/*/[3-9]*  # 删除70%的样本数量,减少训练时间。
$ ls flower_photos/roses | wc -l

开始训练

下载retrain脚本

该脚本会自动下载google Inception v3 模型相关文件。

$ cd ~/tf_files
$ curl -O https://raw.githubusercontent.com/tensorflow/tensorflow/r1.1/tensorflow/examples/image_retraining/retrain.py

启动tensorboard

$ cd ~/tf_files
$ tensorboard --logdir training_summaries &

Note:
This command will fail with the following error if you already have a tensorboard 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"

启动训练脚本

$ cd ~/tf_files
$ python retrain.py \--bottleneck_dir=bottlenecks \
  --how_many_training_steps=500 \
  --model_dir=inception \
  --summaries_dir=training_summaries/basic \
  --output_graph=retrained_graph.pb \
  --output_labels=retrained_labels.txt \
  --image_dir=flower_photos

如果不添加--how_many_training_steps=500,默认值为4000。

启动浏览器查看tensorboard

等待~/tf_files/bottlenecks中的bottlenecks文件生成结束后,可以启动浏览器,在地址栏中输入localhost:6006并回车,来查看训练进度。

小结

The retraining script will write out a version of the Inception v3 network with a final layer retrained to your categories to tf_files/retrained_graph.pb and a text file containing the labels to tf_files/retrained_labels.txt.
该图像识别模型,训练后的图像识别准确率应该在85%到99%。

测试重新训练的模型

$ cd ~/tf_files
$ curl -L https://goo.gl/3lTKZs > label_image.py
$ python label_image.py flower_photos/roses/2414954629_3708a1a04d.jpg 

你应该看到类似以下的结果:

daisy (score = 0.99071)
sunflowers (score = 0.00595)
dandelion (score = 0.00252)
roses (score = 0.00049)
tulips (score = 0.00032)

参考

TensorFlow For Poets

Retrain a tensorflow model based on Inception v3相关推荐

  1. Tensorflow(七)Retrain Google Inception V3

    1.下载Inception V3模型 Download-Link 在tensorflow官网中可以直接下载,下载完压缩包以后解压,注意不要删除这个压缩包,后面可能会用到,然后在同目录下创建一个log文 ...

  2. tensorflow实现inception V3

    一.Inception V3结构介绍 1.Inception网络结构 在上图中下一层的输入是上一层的输出,在Inception V3中采用下面两种结构来减少图片的尺寸 在Inception V3中,卷 ...

  3. tensorflow实现猫狗分类器(三)Inception V3迁移学习

    部分内容来自 博主史丹利复合田的Keras 入门课6 – 使用Inception V3模型进行迁移学习 地址:https://blog.csdn.net/tsyccnh/article/details ...

  4. win10使用Inception v3进行图像分类TensorFlow学习记录

    win10中构建TensorFlow环境: 下载并安装anaconda环境,具体步骤这里有:spark2.3在Windows10当中来搭建python3的使用环境pyspark,只需要看anacond ...

  5. 【TensorFlow系列】【五】利用inception v3 pb模型文件做预测

    2019独角兽企业重金招聘Python工程师标准>>> 本文介绍如何利用imagenet比赛上训练好的inception v3冻结的pb模型进行inference. 1.下载ince ...

  6. 【Tensorflow】深度学习实战05——Tensorflow实现Inception V3

    [fishing-pan:https://blog.csdn.net/u013921430转载请注明出处] 前言 前些日子在忙其他的事情,一直没有更新自己学习神经网络的博客,就在端午这天更吧!也祝大家 ...

  7. Inception V3 的 tensorflow 实现

    tensorflow 官方给出的实现:models/inception_v3.py at master · tensorflow/models · GitHub 1. 模型结构 首先来看 Incept ...

  8. 1、VGG16 2、VGG19 3、ResNet50 4、Inception V3 5、Xception介绍——迁移学习

    ResNet, AlexNet, VGG, Inception: 理解各种各样的CNN架构 本文翻译自ResNet, AlexNet, VGG, Inception: Understanding va ...

  9. 迁移学习-使用预训练的Inception v3进行宠物分类

    个人博客:http://www.chenjianqu.com/ 原文链接:http://www.chenjianqu.com/show-53.html 迁移学习 迁移学习(Transfer Learn ...

最新文章

  1. Linux 中echo格式控制、重定向 、管道 | 简介
  2. kafka和storm集群的环境安装
  3. python判断字符_python判断字符串是字母 数字 大小写(转载)
  4. VHDL硬件描述语言
  5. Dynamips 简介
  6. Smarty目录结构和子目录路径问题
  7. Netty 4.x – ByteBuf
  8. vue新版router.addRoute基础用法
  9. Api容器在应用架构演化中的用途
  10. centos上安装updatedb,command not found
  11. 数据结构-栈(先进后出表)
  12. 快速图像增强的简便大法来了,英伟达开源新库代号“DALI”| CVPR 18
  13. 关于GPS信息在谷歌地图上实时更新位置信息的问题
  14. python抽奖教程_python实现抽奖小程序
  15. android闹铃唤醒软件,温柔唤醒闹钟app_温柔的闹钟铃声有哪些_华为智能闹钟智能唤醒-多特软件站安卓网...
  16. Oracle 锁详解(lock)
  17. 嵌入式微处理器的分类有哪些?
  18. 下载c语言软件后怎么解压,手机怎么解压文件 盘点常用手机压缩打包解压文件应用...
  19. Ubuntu出现Authentication failure(认证失败)的解决方法(转)
  20. 《网络攻防》 免杀原理与实践

热门文章

  1. NPDP认证|如何实现产品的组合管理?
  2. HTML文件引入外部CSS文件时路径的写法总结
  3. opencv的cvtColor函数Lab转RGB源码解析及结果截断处理解决
  4. 如何批量提取 PDF 文档内容,将 PDF 格式文档转为 Txt 文本格式
  5. 优酷的视频地址获取接口
  6. Python图片验证码自动识别
  7. 阿里+中科院提出:将角度margin引入到对比学习目标函数中并建模句子间不同相似程度...
  8. ECM技术学习:重叠块运动补偿(Overlapped Block Motion Compensation)
  9. 关于微信里wx.getUserInfo获取用户信息都是拼音的转成中文方法
  10. 笔记本电脑查看几个卡槽,支持最大内存,内存条参数详细步骤,开启双通道条件