Tensorflow加载goodle的inception-v3模型
2018-03-01 23:04
435 查看
import tensorflow as tf import os import tarfile import requests # inception模型下载地址 inception_pretrain_module_url = 'http://download.tensorflow.org/models/image/imagenet/inception-2015-12-05.tgz' # 模型存储地址 inception_pretrain_module_dir = 'inception_model' if not os.path.exists(inception_pretrain_module_dir): os.mkdir(inception_pretrain_module_dir) # 获取文件名,以及文件路径 filename = inception_pretrain_module_url.split('/')[-1] filepath = os.path.join(inception_pretrain_module_dir, filename) # 下载模型 if not os.path.exists(filepath): print('download', filename) r = requests.get(inception_pretrain_module_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_module_dir) # 模型结构存放文件 log_dir = 'inception_log' if not os.path.exists(log_dir): os.mkdir(log_dir) # classify_image_graph_def.pb为Google训练好的模型 inception_graph_def_file = os.path.join(inception_pretrain_module_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()
相关文章推荐
- tensorflow之inception_v3模型的部分加载及权重的部分恢复(23)---《深度学习》
- TensorFlow 深度学习框架(9)-- 经典卷积网络模型 : LeNet-5 模型 & Inception-v3 模型
- TensorFlow 深度学习框架(9)-- 经典卷积网络模型 : LeNet-5 模型 & Inception-v3 模型
- TensorFlow 深度学习框架(9)-- 经典卷积网络模型 : LeNet-5 模型 & Inception-v3 模型
- TensorFlow 深度学习框架(9)-- 经典卷积网络模型 : LeNet-5 模型 & Inception-v3 模型
- TensorFlow 深度学习框架(9)-- 经典卷积网络模型 : LeNet-5 模型 & Inception-v3 模型
- TensorFlow 深度学习框架(9)-- 经典卷积网络模型 : LeNet-5 模型 & Inception-v3 模型
- TensorFlow 深度学习框架(9)-- 经典卷积网络模型 : LeNet-5 模型 & Inception-v3 模型
- TensorFlow 深度学习框架(9)-- 经典卷积网络模型 : LeNet-5 模型 & Inception-v3 模型
- Tensorflow 的安装和用InceptionV3训练新的图像分类模型
- TensorFlow 深度学习框架(9)-- 经典卷积网络模型 : LeNet-5 模型 & Inception-v3 模型
- TensorFlow 深度学习框架(9)-- 经典卷积网络模型 : LeNet-5 模型 & Inception-v3 模型
- TensorFlow 深度学习框架(9)-- 经典卷积网络模型 : LeNet-5 模型 & Inception-v3 模型
- TensorFlow 深度学习框架(9)-- 经典卷积网络模型 : LeNet-5 模型 & Inception-v3 模型
- Tensorflow实例:Inception-v3模型
- TensorFlow 深度学习框架(9)-- 经典卷积网络模型 : LeNet-5 模型 & Inception-v3 模型
- TensorFlow 深度学习框架(9)-- 经典卷积网络模型 : LeNet-5 模型 & Inception-v3 模型
- TensorFlow 深度学习框架(9)-- 经典卷积网络模型 : LeNet-5 模型 & Inception-v3 模型
- TensorFlow 深度学习框架(9)-- 经典卷积网络模型 : LeNet-5 模型 & Inception-v3 模型
- tensorflow学习笔记十六:tensorflow官方文档学习 Image Recognition(Inception v3模型)