下载inception v3 google训练好的模型并解压08-3

import tensorflow as tf
import os
import tarfile
import requests

#模型下载地址
inception_pretrain_model_url=‘http://download.tensorflow.org/models/image/imagenet/inception-2015-12-05.tgz‘

#模型存放地址
inception_pretrain_model_dir="inception_model"
if not os.path.exists(inception_pretrain_model_dir):
    os.makedirs(inception_pretrain_model_dir)

#获取文件名以及文件路径
filename=inception_pretrain_model_url.split(‘/‘)[-1]
filepath=os.path.join(inception_pretrain_model_dir, filename)

#下载模型
if not os.path.exists(filepath):
    print("download:", filename)
    r=requests.get(inception_pretrain_model_url, stream=True)
    with open(filepath, ‘wb‘) as f:
        for chunk in r.iter_content(chunk_size=1024):
            if chunk:
                f.write(chunk)
print("finish: ",filename)
#解压文件
tarfile.open(filepath, ‘r:gz‘).extractall(inception_pretrain_model_dir)

#模型结构存放文件
log_dir=‘inception_log‘
if not os.path.exists(log_dir):
    os.makedirs(log_dir)

#classify_image_graph_def.pb为google训练好的模型
inception_graph_def_file=os.path.join(inception_pretrain_model_dir, ‘classify_image_graph_def.pb‘)
with tf.Session() as sess:
    #创建一个图来保存google训练好的模型
    with tf.gfile.FastGFile(inception_graph_def_file, ‘rb‘) as f:
        graph_def=tf.GraphDef()
        graph_def.ParseFromString(f.read())
        tf.import_graph_def(graph_def, name=‘‘)
    #保存图的结构
    writer=tf.summary.FileWriter(log_dir, sess.graph)
    writer.close()

这里使用了requests库进行抓取并保存数据,如果要用py下载文件,都可以用这种方式进行下载;

使用tarfile库进行解压,使用tf.gfile tf.GraphDef()等进行图的存储。

原文地址:https://www.cnblogs.com/go-ahead-wsg/p/12632993.html

时间: 2024-08-19 14:18:38

下载inception v3 google训练好的模型并解压08-3的相关文章

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

ResNet, AlexNet, VGG, Inception: 理解各种各样的CNN架构 本文翻译自ResNet, AlexNet, VGG, Inception: Understanding various architectures of Convolutional Networks,原作者保留版权 卷积神经网络在视觉识别任务上的表现令人称奇.好的CNN网络是带有上百万参数和许多隐含层的"庞然怪物".事实上,一个不好的经验规则是:网络越深,效果越好.AlexNet,VGG,Inc

脸型分类-Face shape classification using Inception v3

本文链接:https://blog.csdn.net/u011961856/article/details/77984667函数解析github 代码:https://github.com/adonistio/inception-face-shape-classifier CLASSIFY_FACE.py1用于运行训练好的Inception model,对输入图像进行分类. CLASSIFY_FACE_CONFUSION.py1与CLASSIFY_FACE.PY类似,但是讲述如结果和一个困惑度矩

caffe初步实践---------使用训练好的模型完成语义分割任务

caffe刚刚安装配置结束,乘热打铁! (一)环境准备 前面我有两篇文章写到caffe的搭建,第一篇cpu only ,第二篇是在服务器上搭建的,其中第二篇因为硬件环境更佳我们的步骤稍显复杂.其实,第二篇也仅仅是caffe的初步搭建完成,还没有编译python接口,那么下面我们一起搞定吧! 首先请读者再回过头去看我的<Ubuntu16.04安装配置Caffe>( http://www.cnblogs.com/xuanxufeng/p/6150593.html  ) 在这篇博文的结尾,我们再增加

tensorflow 1.0 学习:用别人训练好的模型来进行图像分类

谷歌在大型图像数据库ImageNet上训练好了一个Inception-v3模型,这个模型我们可以直接用来进来图像分类. 下载地址:https://storage.googleapis.com/download.tensorflow.org/models/inception_dec_2015.zip 下载完解压后,得到几个文件: 其中的classify_image_graph_def.pb 文件就是训练好的Inception-v3模型. imagenet_synset_to_human_label

python 使用新训练好的模型进行分类

6.在python中使用已经训练好的模型. Caffe只提供封装好的imagenet模型,给定一副图像,直接计算出图像的特征和进行预测.首先需要下载模型文件. Python代码如下: from caffe import imagenet from matplotlib import pyplot # Set the right path to your model file, pretrained model # and the image you would like to classify.

ubuntu16.04 使用tensorflow object detection训练自己的模型

一.构建自己的数据集 1.格式必须为jpg.jpeg或png. 2.在models/research/object_detection文件夹下创建images文件夹,在images文件夹下创建train和val两个文件夹,分别存放训练集图片和测试集图片. 3.下载labelImg目标检测标注工具 (1)下载地址:https://github.com/tzutalin/labelImg (2)由于LabelImg是用Python编写的,并使用Qt作为其图形界面. 因此,python2安装qt4:

【猫狗数据集】使用预训练的resnet18模型

数据集下载地址: 链接:https://pan.baidu.com/s/1l1AnBgkAAEhh0vI5_loWKw提取码:2xq4 创建数据集:https://www.cnblogs.com/xiximayou/p/12398285.html 读取数据集:https://www.cnblogs.com/xiximayou/p/12422827.html 进行训练:https://www.cnblogs.com/xiximayou/p/12448300.html 保存模型并继续进行训练:htt

转载:tensorflow保存训练后的模型

训练完一个模型后,为了以后重复使用,通常我们需要对模型的结果进行保存.如果用Tensorflow去实现神经网络,所要保存的就是神经网络中的各项权重值.建议可以使用Saver类保存和加载模型的结果. 1.使用tf.train.Saver.save()方法保存模型 tf.train.Saver.save(sess, save_path, global_step=None, latest_filename=None, meta_graph_suffix='meta', write_meta_graph

如何下载谷歌地球(Google Earth)中的卫星地图

一.准备工作 安装水经注万能地图下载器,如果没有安装本软件,可以百度"水经注软件"到官方网站下载. 二.下载地图 这里以下载"四川省"谷歌地球中的卫星地图为例. 启动水经注万能地图下载器,首先选择谷歌地球在线地图. 方法一:默认左下角已存在"谷歌地球",直接切换到"谷歌地球"即可,如下图. 方法二:直接选择"在线地图"->"卫星"->"卫星.谷歌地球",如