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 PIL中ImageFilter模塊圖片濾波處理和使用方法
這篇文章主要介紹PIL中ImageFilter模塊幾種圖片濾波處理和使用方法,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2023-11-11解決Numpy中sum函數(shù)求和結(jié)果維度的問題
今天小編大家分享一篇解決Numpy中sum函數(shù)求和結(jié)果維度的問題,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-12-12關(guān)于Python中 循環(huán)器 itertools的介紹
循環(huán)器是對象的容器,包含有多個對象。通過調(diào)用循環(huán)器的next()方法 (__next__()方法,在Python 3.x中),循環(huán)器將依次返回一個對象。直到所有的對象遍歷窮盡,循環(huán)器將舉出StopIteration錯誤。這篇文章將對此做一個詳細介紹,感興趣的小伙伴請參考下面文字內(nèi)容2021-09-09簡單的Python2.7編程初學經(jīng)驗總結(jié)
這篇文章主要是作者寫給Python2.7編程初學者的經(jīng)驗總結(jié),側(cè)重于包管理、代碼調(diào)試等實際使用方面,需要的朋友可以參考下2015-04-04Tensorflow中批量讀取數(shù)據(jù)的案列分析及TFRecord文件的打包與讀取
這篇文章主要介紹了Tensorflow中批量讀取數(shù)據(jù)的案列分析及TFRecord文件的打包與讀取,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2020-06-06Python?matplotlib?seaborn繪圖教程詳解
Seaborn是在matplotlib的基礎(chǔ)上進行了更高級的API封裝,從而使得作圖更加容易,在大多數(shù)情況下使用seaborn就能做出很具有吸引力的圖。本文將詳細講解如何利用Seaborn繪制圖表,需要的可以參考一下2022-03-03Python數(shù)據(jù)結(jié)構(gòu)列表
這篇文章主要介紹了Python數(shù)據(jù)結(jié)構(gòu)列表,本文重點內(nèi)容主要是對列表數(shù)據(jù)結(jié)構(gòu)的使用,在Python中,序列是一組按順序排列的值。Python?有?3?種內(nèi)置的序列類型:字符串、?元組和列表,下面一起進入文章了解更詳細內(nèi)容吧,需要的小伙伴可以參考一下</P><P>2021-12-12