【Tensorflow】如何有效的查看已有的pb模型文件?

一种简单的办法是直接打开(然后却是一堆二进制)。


重新加载模型文件,并输出定义

model = 'model.pb'
with tf.Session() as sess:
    with open(model, 'rb') as model_file:
        graph_def = tf.GraphDef()
        graph_def.ParseFromString(f.read())
        print(graph_def)

采用上述的方式可以在新的会话中重新加载本地的模型文件(pb),然后二进制解析后,输出可以看到结果。但是如果网络层结构十分复杂,那么这种显示方式就会比较难以阅读。


重新加载模型文件,并使用Tensorboard进行可视化处理

from tensorflow.python.platform import gfile
model = 'model.pb'
graph = tf.get_default_graph()
graph_def = graph.as_graph_def()
graph_def.ParseFromString(gfile.FastGFile(model, 'rb').read())
tf.import_graph_def(graph_def, name='graph')
summaryWriter = tf.summary.FileWriter('log/', graph)

然后会在你的log文件夹下面生成文件。在终端中执行

tensorboard --logdir DIR --host IP --port PORT

一般情况下,不设置hostport,就会在localhost:6006启动。DIR是路径(不加引号)。

上面的例子:

tensorboard --logdir log

然后在浏览器中访问localhost:6006就可以可视化你的网络结构了。

  • 14
    点赞
  • 38
    收藏
    觉得还不错? 一键收藏
  • 5
    评论
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值