tensorflow从pb文件中导出权重
import tensorflow as tf
from tensorflow.python.platform import gfile
#path to your .pb file
GRAPH_PB_PATH = './model/tensorflow_inception_v3_stripped_optimized_quantized.pb'
with tf.Session(config=config) as sess:
print("load graph")
with gfile.FastGFile(GRAPH_PB_PATH,'rb') as f:
graph_def = tf.GraphDef()
graph_def.ParseFromString(f.read())
sess.graph.as_default()
tf.import_graph_def(graph_def, name='')
graph_nodes=[n for n in graph_def.node]
wts = [n for n in graph_nodes if n.op=='Const']
from tensorflow.python.framework import tensor_util
for n in wts:
print("Name of the node - %s" % n.name)
print("Value - ")
print(tensor_util.MakeNdarray(n.attr['value'].tensor))
参考链接:

浙公网安备 33010602011771号