1. # coding: utf-8
  2.  
  3. import tensorflow as tf
  4. import os
  5. import tarfile
  6. import requests
  7.  
  8. #inception模型下载地址
  9. inception_pretrain_model_url = 'http://download.tensorflow.org/models/image/imagenet/inception-2015-12-05.tgz'
  10.  
  11. #模型存放地址
  12. inception_pretrain_model_dir = "inception_model"
  13. if not os.path.exists(inception_pretrain_model_dir):
  14. os.makedirs(inception_pretrain_model_dir)
  15.  
  16. #获取文件名,以及文件路径
  17. filename = inception_pretrain_model_url.split('/')[-1]
  18. filepath = os.path.join(inception_pretrain_model_dir, filename)
  19.  
  20. #下载模型
  21. if not os.path.exists(filepath):
  22. print("download: ", filename)
  23. r = requests.get(inception_pretrain_model_url, stream=True)
  24. with open(filepath, 'wb') as f:
  25. for chunk in r.iter_content(chunk_size=1024):
  26. if chunk:
  27. f.write(chunk)
  28. print("finish: ", filename)
  29. #解压文件
  30. tarfile.open(filepath, 'r:gz').extractall(inception_pretrain_model_dir)
  31.  
  32. #模型结构存放文件
  33. log_dir = 'inception_log'
  34. if not os.path.exists(log_dir):
  35. os.makedirs(log_dir)
  36.  
  37. #classify_image_graph_def.pb为google训练好的模型
  38. inception_graph_def_file = os.path.join(inception_pretrain_model_dir, 'classify_image_graph_def.pb')
  39. with tf.Session() as sess:
  40. #创建一个图来存放google训练好的模型
  41. with tf.gfile.FastGFile(inception_graph_def_file, 'rb') as f:
  42. graph_def = tf.GraphDef()
  43. graph_def.ParseFromString(f.read())
  44. tf.import_graph_def(graph_def, name='')
  45. #保存图的结构
  46. writer = tf.summary.FileWriter(log_dir, sess.graph)
  47. writer.close()

Tensorflow学习教程------下载图像识别模型inceptionV3的更多相关文章

  1. Tensorflow学习教程------过拟合

    Tensorflow学习教程------过拟合   回归:过拟合情况 / 分类过拟合 防止过拟合的方法有三种: 1 增加数据集 2 添加正则项 3 Dropout,意思就是训练的时候隐层神经元每次随机 ...

  2. Tensorflow学习教程------读取数据、建立网络、训练模型,小巧而完整的代码示例

    紧接上篇Tensorflow学习教程------tfrecords数据格式生成与读取,本篇将数据读取.建立网络以及模型训练整理成一个小样例,完整代码如下. #coding:utf-8 import t ...

  3. ASP.NET MVC 5 学习教程:添加模型

    原文 ASP.NET MVC 5 学习教程:添加模型 起飞网 ASP.NET MVC 5 学习教程目录: 添加控制器 添加视图 修改视图和布局页 控制器传递数据给视图 添加模型 创建连接字符串 通过控 ...

  4. Tensorflow学习教程------代价函数

    Tensorflow学习教程------代价函数   二次代价函数(quadratic cost): 其中,C表示代价函数,x表示样本,y表示实际值,a表示输出值,n表示样本的总数.为简单起见,使用一 ...

  5. 深度学习教程 | Seq2Seq序列模型和注意力机制

    作者:韩信子@ShowMeAI 教程地址:http://www.showmeai.tech/tutorials/35 本文地址:http://www.showmeai.tech/article-det ...

  6. tensorflow 学习教程

    tensorflow 学习手册 tensorflow 学习手册1:https://cloud.tencent.com/developer/section/1475687 tensorflow 学习手册 ...

  7. Tensorflow学习教程------利用卷积神经网络对mnist数据集进行分类_利用训练好的模型进行分类

    #coding:utf-8 import tensorflow as tf from PIL import Image,ImageFilter from tensorflow.examples.tut ...

  8. Tensorflow学习教程------模型参数和网络结构保存且载入,输入一张手写数字图片判断是几

    首先是模型参数和网络结构的保存 #coding:utf-8 import tensorflow as tf from tensorflow.examples.tutorials.mnist impor ...

  9. Tensorflow学习教程------创建图启动图

    Tensorflow作为目前最热门的机器学习框架之一,受到了工业界和学界的热门追捧.以下几章教程将记录本人学习tensorflow的一些过程. 在tensorflow这个框架里,可以讲是若数据类型,也 ...

随机推荐

  1. Marvolo Gaunt's Ring(巧妙利用前后缀进行模拟)

    Description Professor Dumbledore is helping Harry destroy the Horcruxes. He went to Gaunt Shack as h ...

  2. jquery 版本冲突解决办法

    <!-- 引入1.6.4版的jq --> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jq ...

  3. MFC中隐藏和显示光标的切换

    函数原型:int ShowCursor(BOOL bShow): 参数: bShow:确定内部的显示计数器是增加还是减少,如果bShow为TRUE,则显示计数器增加1,如果bShow为FALSE,则计 ...

  4. zabbix 日志

    /var/log/zabbix/ tail -f /var/log/zabbix/zabbix_server.log tail -f /var/log/zabbix/zabbix_agentd.log

  5. “设计型web前端与开发型web前端”有哪些区别?

    学web前端,你弄懂开发型web前端和设计型web前端的区别了吗?今天给大家梳理一下设计型web前端做什么?都要学习什么? 想必大家也会遇到这种情况,要做一个项目,产品经理说产品原型图已经画好了,让我 ...

  6. 网络寻路(DFS)

    Description X 国的一个网络使用若干条线路连接若干个节点.节点间的通信是双向的.某重要数据包,为了安全起见,必须恰好被转发两次到达目的地.该包可能在任意一个节点产生,我们需要知道该网络中一 ...

  7. 修改完Apache的配置文件,重启Apache后,仍无法打开网页

    在修改Apache的配置文件时,由于某些非正常操作,导致httpd.conf文件非正常打开,需要继续enter进入, 这是会在httpd.conf同级目录中产生一个隐藏文件,.httpd.conf.s ...

  8. Bandwagon 安装 Mysql 数据库

    Bandwagon 安装 Mysql 数据库 1.搬瓦工系统准备 建议使用版本Centos6 x86_64,安装完成后,使用远程登陆软件登陆. 2.安装编译工具及库文件 yum -y install ...

  9. mac安装浏览器同步测试工具

    1.安装node.js (1)打开终端,输入以下命令安装Homebrew ruby -e “$(curl -fsSL https://raw.githubusercontent.com/Homebre ...

  10. AD软件将PCB中的元器件旋转45度