深度学习涉及到图像就少不了CNN模型,前面我做过几个关于图像的练习,使用的CNN网络也不够”Deeper”。我在做对象检测练习( Object Detection)时,需要用到更复杂的网络结构。本帖就使用TensorBoard看看Inception V3模型的网络结构。
Inception (GoogLeNet)是Google 2014年发布的Deep Convolutional Neural Network,其它几个流行的CNN网络还有QuocNet、AlexNet、BN-Inception-v2、VGG、ResNet等等。
Inception V3模型源码定义:tensorflow/contrib/slim/python/slim/nets/inception_v3.py
训练大的网络模型很耗资源,幸亏TensorFlow支持分布式:
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模型
inception_pretrain_model_dir = "inception_pretrain"
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("开始下载: ", 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("下载完成, 开始解压: ", filename)
tarfile.open(filepath, 'r:gz').extractall(inception_pretrain_model_dir)
# TensorBoard log目录
log_dir = 'inception_log'
if not os.path.exists(log_dir):
os.makedirs(log_dir)
# 加载inception graph
inception_graph_def_file = os.path.join(inception_pretrain_model_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.train.SummaryWriter(log_dir, sess.graph)
writer.close()
使用TensorBoard查看Graph:
1 | $tensorboard--logdirinception_log |
---|
浏览器访问:http://127.0.0.1:6006
Share the post "可视化Google Inception V3模型的网络结构"