天天看點

tensorflow的pb檔案轉化為pbtxt

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)
           

繼續閱讀