国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

tensorflow 實現(xiàn)從checkpoint中獲取graph信息

2020-02-15 21:17:15
字體:
供稿:網(wǎng)友

代碼:

import tensorflow as tf sess = tf.Session()check_point_path = 'variables' saver = tf.train.import_meta_graph('variables/save_variables.ckpt.meta') saver.restore(sess, tf.train.latest_checkpoint(check_point_path)) graph = tf.get_default_graph() #print(graph.get_operations()) #with open('op.txt','a') as f:# f.write(str(graph.get_operations()))op1 = graph.get_tensor_by_name('fully_connected/biases:0')print(op1)

使用函數(shù)graph.get_operations()獲取ckpt.meta中保存的graph中的所有operation,而tensor_name為'op_name:0'。

然后使用graph.get_tensor_by_name('op_name:0') 獲取tensor信息。

代碼從ckpt文件中獲取保存的variable的數(shù)據(jù)(tensor的name和value):

import osimport tensorflow as tffrom tensorflow.python import pywrap_tensorflowcheck_point_path = 'variables'#checkpoint_path = os.path.join(logs_train_dir, 'model.ckpt')ckpt = tf.train.get_checkpoint_state(checkpoint_dir=check_point_path)checkpoint_path = os.path.join('.', ckpt.model_checkpoint_path)#print(ckpt.model_checkpoint_path)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) #print(reader.get_tensor(key))

法二:

from tensorflow.python.tools.inspect_checkpoint import print_tensors_in_checkpoint_file print_tensors_in_checkpoint_file("variables/save_variables.ckpt",tensor_name='', all_tensors=False, all_tensor_names=False)

注意:tf.train.latest_checkpoint(check_point_path) 方法用來獲取最后一次ckeckpoint的路徑,等價于

ckpt = tf.train.get_checkpoint_state(check_point_path)ckpt.model_checkpoint_path

不能將tf.train.latest_checkpoint與tf.train.get_checkpoint_state 搞混了

以上這篇tensorflow 實現(xiàn)從checkpoint中獲取graph信息就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持武林站長站。

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 伊川县| 安新县| 玛曲县| 双桥区| 浏阳市| 遂溪县| 安达市| 许昌市| 独山县| 正阳县| 屏东市| 屏南县| 海原县| 新竹县| 香格里拉县| 麦盖提县| 巴彦淖尔市| 宜君县| 达孜县| 阜宁县| 赤峰市| 阿克苏市| 获嘉县| 延长县| 同心县| 寿宁县| 内乡县| 噶尔县| 隆尧县| 新干县| 内黄县| 鹤岗市| 金山区| 岳阳县| 荥阳市| 德惠市| 开平市| 五峰| 隆化县| 阳曲县| 连江县|