发表于 2018-04-19 | Edited on 2018-09-14 | 分类于 tensorflow | 评论数: Tensorflow学习9-1:谷歌inception-v3模型之下载模型和查看结构 1234567891011import tensorflow as tfimport osimport tarfileimport requests#模型下载地址MOD_URL = "http://download.tensorflow.org/models/image/imagenet/inception-2015-12-05.tgz"#模型存放目录MOD_DIR = "D:/Tensorflow/models/inception/"#模型结构存放目录LOG_DIR = "D:/Tensorflow/logs/inception/" 12345678910111213141516171819202122232425262728293031323334353637if not os.path.exists(MOD_DIR): os.makedirs(MOD_DIR) #取得文件名,以及完整路径file_name = MOD_URL.split("/")[-1]file_path = os.path.join(MOD_DIR, file_name)#file_path = MOD_DIR + file_name#下载模型if not os.path.exists(file_path): print("download: ", file_name) r = requests.get(MOD_URL, stream=True) with open(file_path, "wb") as f: for chunk in r.iter_content(chunk_size=1024): if(chunk): f.write(chunk)print("finish: ", file_name)#解压模型文件到指定目录tarfile.open(file_path, "r:gz").extractall(MOD_DIR)#存放模型结构(用tensorboard查看)if not os.path.exists(LOG_DIR): os.makedirs(LOG_DIR) # 解压后的xxx.pb是训练好的模型inception_model_path = os.path.join(MOD_DIR, "classify_image_graph_def.pb")with tf.Session() as sess: #创建一个图来存放google训练好的模型 with tf.gfile.FastGFile(inception_model_path, "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() finish: inception-2015-12-05.tgz 结构如下图 ꧁༺The༒End༻꧂