-
大小: 1KB文件類型: .py金幣: 2下載: 1 次發布日期: 2021-06-18
- 語言: Python
- 標簽: tensorflow??ckpt??pb??模型轉化??
資源簡介
把tensorflow保存的checkpoint類型模型凍結,轉化為.pb模型輸出。調用方法參見我的博文https://blog.csdn.net/weixin_41864878/article/details/84957681
代碼片段和文件信息
import?argparse
import?tensorflow?as?tf
from?tensorflow.python.framework?import?graph_util
def?freeze_graph(input_checkpointoutput_graph?output_node_names):
????‘‘‘
????To?convert?the?TensorFlow?checkpoint?files?to?froze?graph
????:param?input_checkpoint:
????:param?output_graph:
????:return:
????‘‘‘
????saver?=?tf.train.import_meta_graph(input_checkpoint?+?‘.meta‘?clear_devices=True)
?
????with?tf.Session()?as?sess:
????????saver.restore(sess?input_checkpoint)
????????output_graph_def?=?graph_util.convert_variables_to_constants(??
????????????sess=sess
????????????input_graph_def=sess.graph_def#?:sess.graph_def
????????????output_node_names=output_node_names.split(““))#
?
????????with?tf.gfile.GFile(output_graph?“wb“)?as?f:?
??????????
評論
共有 條評論