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通過(guò)getopt模塊如何獲取執(zhí)行的命令參數(shù)詳解
這篇文章主要給大家介紹了關(guān)于python通過(guò)getopt模塊如何獲取執(zhí)行的命令參數(shù)的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧。2017-12-12
在python中利用KNN實(shí)現(xiàn)對(duì)iris進(jìn)行分類的方法
今天小編就為大家分享一篇在python中利用KNN實(shí)現(xiàn)對(duì)iris進(jìn)行分類的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2018-12-12
淺析Python中正則表達(dá)式函數(shù)search()和match()的使用
在Python中,正則表達(dá)式是處理字符串的強(qiáng)大工具,search()和match()是Python標(biāo)準(zhǔn)庫(kù)中re模塊中兩個(gè)常用的正則表達(dá)式方法,本文將詳細(xì)講解這兩個(gè)方法的使用,需要的可以參考一下2023-08-08
python處理二進(jìn)制數(shù)據(jù)的方法
這篇文章主要介紹了python處理二進(jìn)制數(shù)據(jù)的方法,涉及Python針對(duì)二進(jìn)制數(shù)據(jù)的相關(guān)操作技巧,需要的朋友可以參考下2015-06-06
python3中calendar返回某一時(shí)間點(diǎn)實(shí)例講解
在本篇內(nèi)容里小編給大家整理了關(guān)于python3中calendar返回某一時(shí)間點(diǎn)實(shí)例講解內(nèi)容,有興趣的朋友們可以參考學(xué)習(xí)下。2020-11-11
python進(jìn)程間通信的項(xiàng)目實(shí)踐
本文主要介紹了python進(jìn)程間通信的項(xiàng)目實(shí)踐,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2023-03-03
總結(jié)的幾個(gè)Python函數(shù)方法設(shè)計(jì)原則
這篇文章主要介紹了總結(jié)的幾個(gè)Python函數(shù)方法設(shè)計(jì)原則,本文講解了每個(gè)函數(shù)只做一件事、保持簡(jiǎn)單、保持簡(jiǎn)短、輸入使用參數(shù)、輸出使用return語(yǔ)句等內(nèi)容,需要的朋友可以參考下2015-06-06
Python實(shí)現(xiàn)批量提取PPT中的文字
這篇文章主要為大家詳細(xì)介紹了如何使用Python中的pptx和docx庫(kù)來(lái)將PPT中的文字提取到Word中,文中的示例代碼講解詳細(xì),有需要的可以參考下2024-03-03

