利用tensorboard查看pb模型图

本文介绍了如何利用TensorFlow的pb文件查看模型图。首先,模型图和参数被保存在一个pb文件中,通过特定代码可以加载并查看模型图。其次,如果模型是通过estimator的export_saved_model或tf.saved_model保存的,会包含saved_model.pb和variables目录,同样有方法导出模型图。最后,使用tensorboard --logdir ./log --host 0.0.0.0命令可以启动TensorBoard以观察图结构。
摘要由CSDN通过智能技术生成

1. 模型图和参数全保存在一个pb文件里(即freeze出来的模型),查看模型图代码如下:

import tensorflow as tf
with tf.Session() as sess:
    model_filename ='model/freezon.pb'
    with tf.gfile.GFile(model_filename, 'rb') as f:
        graph_def = tf.GraphDef()
        graph_def.ParseFromString(f.read())
        g_in = tf.import_graph_def(graph_def)
     train_writer = tf.summary.FileWriter("./log")
     train_writer.add_graph(sess.graph)
        train_writer.flush()
        train_writer.close()

2. 使用estimator的export_saved_model或tf.saved_model保存的模型,包含saved_model.pb和varibles目录,导出模型图代码如下:

import tensorflow as tf
from tensorflow.core.protobuf import saved_model_pb2
from tensorflow.python.util import compat
from tensorflow.python.framework import ops

model_path = "./1578003200/saved_model.pb"
with tf.Session(graph=ops.Graph()) as sess:
    with tf.gfile.GFile(model_path, &#
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值