利用tensorflow在tensorboard中可视化图结构

在tensorboard中可视化图结构

可视化pb模型的图

import tensorflow as tf
import os
pb_model = "your_pb_model_path"
graph = tf.get_default_graph()
graph_def = graph.as_graph_def()
graph_def.ParseFromString(tf.gfile.FastGFile(pb_model, 'rb').read())
tf.import_graph_def(graph_def, name='graph')
graph_log_path = 'log/pb_model_log'
if os.path.exists(graph_log_path):
    os.rmdir(graph_log_path)
if not os.path.isdir(graph_log_path):  # Create the log directory if it doesn't exist
    os.makedirs(graph_log_path)
summaryWriter = tf.summary.FileWriter(graph_log_path, graph)

可视化meta图

import tensorflow as tf
import os
os.environ["CUDA_VISIBLE_DEVICES"] = "3"

meta_file = "your_meta_file_path"
graph_log_path = "log/your_log_dir"
if os.path.exists(graph_log_path):
    os.rmdir(graph_log_path)
if not os.path.isdir(graph_log_path):  # Create the log directory if it doesn't exist
    os.makedirs(graph_log_path)
g = tf.Graph()
with g.as_default() as g:
    tf.train.import_meta_graph(meta_file)
with tf.Session(graph=g) as sess:
    file_writer = tf.summary.FileWriter(logdir=graph_log_path, graph=g)

查看ckpt里面的变量名和值

import os
import tensorflow as tf
from tensorflow.python import pywrap_tensorflow

checkpoint_path = "your_ckpt_file_path"
# Read data from checkpoint file
reader = pywrap_tensorflow.NewCheckpointReader(checkpoint_path)
var_to_shape_map = reader.get_variable_to_shape_map()
# Print tensor name and values
print("++++++++++++++++++++++++++++++")
for key in var_to_shape_map:
    print("tensor_name:", key)
    #print(reader.get_tensor(key))
print("++++++++++++++++++++++++++++++")
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值