tensorflow查看pb,lite模型函数总结

想要调用他人保存的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()

print

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。。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值