Tensorflow加载goodle的inception-v3模型
2019-04-14 20:31发布
生成海报
import tensorflow as tf
import os
import tarfile
import requests
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)
inception_graph_def_file = os.path.join(inception_pretrain_module_dir, 'classify_image_graph_def.pb')
with tf.Session() as sess:
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()
打开微信“扫一扫”,打开网页后点击屏幕右上角分享按钮