tensorflow学习笔记-从checkpoint中获取graph信息
2018-04-10 17:31
501 查看
代码:
然后使用graph.get_tensor_by_name('op_name:0') 获取tensor信息。
代码从ckpt文件中获取保存的variable的数据(tensor的name和value):import os
import tensorflow as tf
from tensorflow.python import pywrap_tensorflow
check_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)参考博客
Tensorflow Error笔记3
Save tensorflow model: variables not found
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)使用函数graph.get_operations()获取ckpt.meta中保存的graph中的所有operation,而tensor_name为'op_name:0'。
然后使用graph.get_tensor_by_name('op_name:0') 获取tensor信息。
代码从ckpt文件中获取保存的variable的数据(tensor的name和value):import os
import tensorflow as tf
from tensorflow.python import pywrap_tensorflow
check_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)参考博客
Tensorflow Error笔记3
Save tensorflow model: variables not found
相关文章推荐
- Web 在线文件管理器学习笔记与总结(1)初始文件以及获取首层目录信息
- ios学习笔记: IOS8解决获取位置坐标信息出错(Error Domain=kCLErrorDomain Code=0)
- [C#学习笔记]获取当前系统的基本信息
- MySQL学习笔记——获取MySQL命令的帮助信息
- (转)IOS 学习笔记 2015-03-23 如何获取IOS程序的系统信息
- Java学习笔记(七)——获取类中方法的信息,java的LinkedList
- ubuntu操作系统学习笔记之获取帮助信息
- Idoc学习笔记----获取查询Idoc信息
- iOS学习笔记(十三)——获取手机信息(UIDevice、NSBundle、NSLocale)
- iOS学习笔记(十三)——获取手机信息(UIDevice、NSBundle、NSLocale)
- Web入侵安全测试与对策学习笔记之(二)——获取目标信息之其他人留下的漏洞—样例程序的缺陷
- python 学习笔记 12 -- 写一个脚本获取城市天气信息
- iOS学习笔记 获取手机信息(UIDevice、NSBundle、NSLocal)
- 安卓学习笔记---【Android】获取手机的基本信息
- iOS学习笔记(十三)——获取手机信息(UIDevice、NSBundle、NSLocale)
- 【Python学习笔记】面向对象编程:获取对象信息
- 【Python】学习笔记——-7.4、获取对象信息
- python学习笔记 获取对象信息
- python 学习笔记 12 -- 写一个脚本获取城市天气信息
- Python学习笔记15:标准库之获取进程信息(os包)