tensorflow ckpt模型和pb模型獲取節(jié)點名稱,及ckpt轉(zhuǎn)pb模型實例
更新時間:2020年01月21日 10:42:38 作者:三寸光陰___
今天小編就為大家分享一篇tensorflow ckpt模型和pb模型獲取節(jié)點名稱,及ckpt轉(zhuǎn)pb模型實例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
ckpt
from tensorflow.python import pywrap_tensorflow
checkpoint_path = 'model.ckpt-8000'
reader = pywrap_tensorflow.NewCheckpointReader(checkpoint_path)
var_to_shape_map = reader.get_variable_to_shape_map()
for key in var_to_shape_map:
print("tensor_name: ", key)
pb
import tensorflow as tf import os model_name = './mobilenet_v2_140_inf_graph.pb' def create_graph(): with tf.gfile.FastGFile(model_name, 'rb') as f: graph_def = tf.GraphDef() graph_def.ParseFromString(f.read()) tf.import_graph_def(graph_def, name='') create_graph() tensor_name_list = [tensor.name for tensor in tf.get_default_graph().as_graph_def().node] for tensor_name in tensor_name_list: print(tensor_name,'\n')
ckpt轉(zhuǎn)pb
def freeze_graph(input_checkpoint,output_graph):
'''
:param input_checkpoint:
:param output_graph: PB模型保存路徑
:return:
'''
output_node_names = "xxx"
saver = tf.train.import_meta_graph(input_checkpoint + '.meta', clear_devices=True)
graph = tf.get_default_graph()
input_graph_def = graph.as_graph_def()
with tf.Session() as sess:
saver.restore(sess, input_checkpoint)
output_graph_def = graph_util.convert_variables_to_constants(
sess=sess,
input_graph_def=input_graph_def,# 等于:sess.graph_def
output_node_names=output_node_names.split(","))
with tf.gfile.GFile(output_graph, "wb") as f:
f.write(output_graph_def.SerializeToString())
print("%d ops in the final graph." % len(output_graph_def.node))
for op in graph.get_operations():
print(op.name, op.values())
以上這篇tensorflow ckpt模型和pb模型獲取節(jié)點名稱,及ckpt轉(zhuǎn)pb模型實例就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
python通過getopt模塊如何獲取執(zhí)行的命令參數(shù)詳解
這篇文章主要給大家介紹了關(guān)于python通過getopt模塊如何獲取執(zhí)行的命令參數(shù)的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧。2017-12-12
在python中利用KNN實現(xiàn)對iris進行分類的方法
今天小編就為大家分享一篇在python中利用KNN實現(xiàn)對iris進行分類的方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-12-12
淺析Python中正則表達式函數(shù)search()和match()的使用
在Python中,正則表達式是處理字符串的強大工具,search()和match()是Python標(biāo)準(zhǔn)庫中re模塊中兩個常用的正則表達式方法,本文將詳細(xì)講解這兩個方法的使用,需要的可以參考一下2023-08-08
總結(jié)的幾個Python函數(shù)方法設(shè)計原則
這篇文章主要介紹了總結(jié)的幾個Python函數(shù)方法設(shè)計原則,本文講解了每個函數(shù)只做一件事、保持簡單、保持簡短、輸入使用參數(shù)、輸出使用return語句等內(nèi)容,需要的朋友可以參考下2015-06-06

