windows下tensorflow两种加载模型的测试数据方法
来源:互联网 发布:kylie jenner 知乎 编辑:程序博客网 时间:2024/06/06 02:32
一、加载多次保存的模型中的某一次模型,而不是latest的一次
global sess
global charcnn
def get_logits_with_value_by_input(start,end):
x=test_x[start:end]
global sess
global charcnn
logits = sess.run(charcnn.predictions, feed_dict={charcnn.input_x: x, charcnn.dropout_keep_prob: 1})
real_labels=test_y[start:end]
real_labels_label=tf.argmax(real_labels,axis=1)
return logits,real_labels_label
with tf.Graph().as_default():
session_config=tf.ConfigProto(allow_soft_placement=True,log_device_placement=False)
sess=tf.Session(config=session_config)
with tf.Session() as sess:
charcnn = charCNN(config.l0, config.num_classes, config.model.conv_layers, config.model.fc_layers,
l2_reg_lambda=0.0)
saver = tf.train.Saver()
#checkpoint_dir = os.path.abspath(os.path.join(out_dir, 'checkpoints'))
if os.path.exists("./run/1513350504/checkpoints/checkpoint"): #一定要用‘/’这个反斜杠
print("Restoring Variables from Checkpoint")
saver = tf.train.import_meta_graph('./run/1513350504/checkpoints/model-1200.meta') #导入验证准确率比较高的某个计算图
saver.restore(sess,'./run/1513350504/checkpoints/model-1200') #加载模型,不加后缀名
else:
print("Can't find the checkpoint.going to stop")
logits,real_labels_label=get_logits_with_value_by_input(0,-1)
print (logits)
print (real_labels_label.eval())
二、直接加载checkpoint中最近latest的模型,(不过有时候模型收敛的不好,latest的模型准确率不高)
with tf.Graph().as_default():
session_config=tf.ConfigProto(allow_soft_placement=True,log_device_placement=False)
sess=tf.Session(config=session_config)
with tf.Session() as sess:
charcnn = charCNN(config.l0, config.num_classes, config.model.conv_layers, config.model.fc_layers,
l2_reg_lambda=0.0)
saver = tf.train.Saver()
#checkpoint_dir = os.path.abspath(os.path.join(out_dir, 'checkpoints'))
if os.path.exists("checkpoint"):
print("Restoring Variables from Checkpoint")
saver.restore(sess, tf.train.latest_checkpoint('checkpoints/')) #还是这种反斜杠
else:
print("Can't find the checkpoint.going to stop")
logits,real_labels_label=get_logits_with_value_by_input(0,-1)
print (logits)
print (real_labels_label.eval())
阅读全文
0 0
- windows下tensorflow两种加载模型的测试数据方法
- TensorFlow 模型保存/载入的两种方法
- TensorFlow下网络模型的存储与加载
- windows下安装tensorflow的简单方法
- Windows下加载CAFFE模型的问题
- TensorFlow Session使用的两种方法
- 【tensorflow】文件队列的两种创建和加载方式
- Windows 下安装 Ubuntu 7.10 的两种方法
- Windows下计算md5的两种方法
- windows下获取mac地址的两种方法
- TensorFlow加载图片的方法
- 5.2 TensorFlow:模型的加载,存储,实例
- Windows下Pycharm使用Tensorflow、Theano和Keras的方法
- Windows下Pycharm使用Tensorflow、Theano和Keras的方法
- windows 下驱动程序加载卸载的方法
- tensorflow: 对variable_scope进行reuse的两种方法
- windows下的tensorflow安装
- Windows下 TensorFlow的安装
- 联想IT监控携手Riverbed打造数字化转型之路
- JAVA基础------实现日期差值的计算
- 中计播客 | 为防止员工加班,无人机都用上了!
- Essential Qt 第十七章 贪吃蛇(上)
- CAST智能分析平台 做软件中的X光透视仪
- windows下tensorflow两种加载模型的测试数据方法
- 利用Easy UI生成异步树以及动态添加标签页
- tensorflow版本的一些区别
- Android多线程AsyncTask入门讲解
- Retroit+rxjava2.0+mvp封装
- Java复习笔记(五)-----实现多重继承
- 转----FPGA做MAC功能,直接挂PHY芯片发送网络报文
- Java高性能缓冲设计 vs Disruptor vs LinkedBlockingQueue
- ioi2000 回文词