tensorflow如何将训练好的ckpt模型做预测?
tensorflow吧
全部回复
仅看楼主
level 2
729006000ma 楼主
模型ckpt已经训练好了,怎么进行测试?
2019年03月12日 02点03分 1
level 3
最好是把模型保存成pb文件,然后读取
2019年03月13日 01点03分 2
怎么保存成pb文件然后读取?
2019年03月13日 03点03分
level 3
# 保存
constant_graph = graph_util.convert_variables_to_constants(sess, sess.graph_def,['output']) # 方括号内填输出节点的名称
pb_file_path = os.path.join(ps.model_path, 'filename.pb')
with tf.gfile.FastGFile(pb_file_path, mode='wb') as f:
f.write(constant_graph.SerializeToString())
# 读取
with tf.gfile.FastGFile('filename.pb', 'rb') as f:
graph_def = tf.GraphDef()
graph_def.ParseFromString(f.read())
tf.import_graph_def(graph_def, name='')
image_placeholder = sess.graph.get_tensor_by_name("image_placeholder:0") # 名称都是你自己定的,自己去找就行了
ouptut = sess.graph.get_tensor_by_name("output:0")
print (sess.run(ouptut, feed_dic={})
2019年03月13日 04点03分 3
level 3
这种东西百度就行了
2019年03月13日 04点03分 4
百度上的代码都太散乱了,刚才你的代码我用了一下,可能没有缩进的原因吧,没有成功运行,求能不能给我一个完整的代码,膜拜大神[泪]
2019年03月13日 08点03分
level 3
2019年03月13日 11点03分 5
关键是你要清楚输入、输出节点的名称
2019年03月13日 11点03分
1