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

