tensorflow的pb文件转化为pbtxt

论坛 期权论坛 脚本     
匿名技术用户   2021-1-5 02:57   11   0
import tensorflow as tf

from tensorflow.python.platform import gfile


#函数功能能,将pb模型转换为pbtxt,转换好后存储到当前目录下,模型名字是protobuf.pbtxt

def convert_pb_to_pbtxt(filename):

with gfile.FastGFile(filename, 'rb') as f:

graph_def = tf.GraphDef()

graph_def.ParseFromString(f.read())

tf.import_graph_def(graph_def, name='')

tf.train.write_graph(graph_def, './', 'protobuf.pbtxt', as_text=True)

return



#函数功能能,将pb模型转换为txt,转换好后存储到txtmodel文件夹下,模型名字是frozen_model_test.txt

def pb_to_txt(frozen_graph_filename):

with tf.gfile.GFile(frozen_graph_filename, "rb") as f:

graph_def = tf.GraphDef()

graph_def.ParseFromString(f.read())

tf.import_graph_def(graph_def, name='')

tf.train.write_graph(graph_def, "./txtmodel ", 'frozen_model_test.txt',as_text=True)



if __name__ == '__main__':

# mygraph = pb_to_txt("frozen_inference_graph.pb")

filepath = 'frozen_inference_graph.pb'

convert_pb_to_pbtxt(filepath)

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:7942463
帖子:1588486
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP