想要调用他人保存的pb或lite模型时往往需要查看模型结构,输入节点类型等,总结一些方法
首先考虑使用Netron看图,还有命令行中使用命令的方式,这里总结利用python
.Lite模型
interpreter = tf.contrib.lite.Interpreter(model_path=model_path)
interpreter.allocate_tensors()
# Get input and output tensors.
input_details = interpreter.get_input_details()
print(str(input_details))
output_details = interpreter.get_output_details()
print(str(output_details))
.pb模型
使用tensorboard
inception_graph_def_file = '/home/huang/huang/model/inception/classify_image_graph_def.pb'
with tf.Session() as sess:
#创建一个图来存放google训练好的模型
with tf.gfile.GFile(inception_graph_def_file, 'rb') as f:
graph_def = tf.GraphDef()
graph_def.ParseFromString(f.read())
tf.import_graph_def(graph_def, name='')
#保存图的结构
writer = tf.summary.FileWriter(log_dir, sess.graph)
writer.close()
with tf.gfile.GFile('/home/huang/huang/model/inception_v3/inception_v3.pb', 'rb') as f:
#with tf.gfile.GFile('/home/model/inception-2015-12-05/quantized_ctpn.pb', 'rb') as f:
graph_def = tf.GraphDef()
graph_def.ParseFromString(f.read())
tf.import_graph_def(graph_def, name='')
print(graph_def)
不知道是我电脑太渣了吗,一运行print就崩了。。
ps
keras的model.summary可以直接看网络结构
吐槽:tensorflow模型存储格式太多,调用方式也一大堆,现在官网教程却基本只写keras。。