学习博客:

# https://www.cnblogs.com/felixwang2/p/9190731.html

 1 # https://www.cnblogs.com/felixwang2/p/9190731.html
 2 # TensorFlow(十四):谷歌图像识别网络inception-v3下载与查看结构
 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 # inception_pretrain_model_url = \'http://download.tensorflow.org/models/inception_v4_2016_09_09.tar.gz\'
11 
12 # 模型存放地址
13 inception_pretrain_model_dir = "inception_model"
14 if not os.path.exists(inception_pretrain_model_dir):
15     os.makedirs(inception_pretrain_model_dir)
16 
17 # 获取文件名,以及文件路径
18 filename = inception_pretrain_model_url.split(\'/\')[-1]
19 filepath = os.path.join(inception_pretrain_model_dir, filename)
20 
21 # 下载模型
22 if not os.path.exists(filepath):
23     print("download: ", filename)
24     r = requests.get(inception_pretrain_model_url, stream=True)
25     with open(filepath, \'wb\') as f:
26         for chunk in r.iter_content(chunk_size=1024):
27             if chunk:
28                 f.write(chunk)
29 print("finish: ", filename)
30 # 解压文件
31 tarfile.open(filepath, \'r:gz\').extractall(inception_pretrain_model_dir)
32 
33 # 模型结构存放文件
34 log_dir = \'inception_log\'
35 if not os.path.exists(log_dir):
36     os.makedirs(log_dir)
37 
38 # classify_image_graph_def.pb为google训练好的模型
39 inception_graph_def_file = os.path.join(inception_pretrain_model_dir, \'classify_image_graph_def.pb\')
40 # inception_graph_def_file = os.path.join(inception_pretrain_model_dir, \'inception_v4.ckpt\')
41 gpu_options = tf.GPUOptions(allow_growth=True)
42 with tf.Session(config=tf.ConfigProto(gpu_options=gpu_options)) as sess:
43     # 创建一个图来存放google训练好的模型
44     with tf.gfile.FastGFile(inception_graph_def_file, \'rb\') as f:
45         graph_def = tf.GraphDef()
46         graph_def.ParseFromString(f.read())
47         tf.import_graph_def(graph_def, name=\'\')
48     # 保存图的结构
49     writer = tf.summary.FileWriter(log_dir, sess.graph)
50     writer.close()

View Code

 

 

 查看网络:

在命令窗口输入:

tensorboard –logdir=D:\documents\pycharm\practice\inception_log

窗口输出:TensorBoard 1.13.1 at http://wangmingze:6006 (Press CTRL+C to quit)

但是我输入这个网址无法访问,宇于是就输入:http://localhost:6006 就进去了。

由于网页截图太小,我就下载图片并上传,这样显示比较清楚。

 




版权声明:本文为juluwangshier原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/juluwangshier/p/11438697.html