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("++++++++++++++++++++++++++++++")