windows下tensorflow两种加载模型的测试数据方法
2017-12-16 10:09
771 查看
一、加载多次保存的模型中的某一次模型,而不是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())
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())
相关文章推荐
- Windows Phone开发经验谈(18)-总结两种滚动条到底部加载数据的方法
- 如何Activiti删除测试数据(存储过程,手动SQL两种方法)
- Android实现listview动态加载数据分页的两种方法
- 【1130】数据结构上机测试1:顺序表的应用 (两种方法) SDUT
- WP--两种滚动条到底部加载数据的方法
- ListView动态加载数据分页(使用Handler+线程和AsyncTask两种方法)
- Tensorflow实战学习(四十九)【模型存储加载,队列线程,加载数据,自定义操作】
- web开发——4.一个完整的web项目和子应用程序的创建以及数据模型操作的两种方法
- 深度学习Caffe实战笔记(21)Windows平台 Faster-RCNN 训练好的模型测试数据
- Druid单机测试与数据加载方法
- Tensorflow学习笔记:用minst数据集训练卷积神经网络并用训练后的模型测试自己的BMP图片
- ADO.NET 中DataTable中加载数据又两种方法
- TensorFlow 模型保存/载入的两种方法
- 学习笔记TF049:TensorFlow 模型存储加载、队列线程、加载数据、自定义操作
- ADO.NET 中DataTable中加载数据又两种方法
- ListView动态加载数据分页(使用Handler+线程和AsyncTask两种方法)
- TensorFlow使用C++加载使用训练好的模型,.cc文件代码实现的相关类及方法总结
- Ext.data.JsonStore使用HttpProxy加载数据时传递参数的两种方法
- 两种方法实现STM32F103向串口一直发送数据(程序源码,已测试)
- ListView动态加载数据分页(使用Handler+线程和AsyncTask两种方法)