Tensorflow使用保存的模型——没有找到.ckpt文件怎么办

最近博主需要使用已经训练好的模型,网上搜的教程几乎全需要用到model.ckpt文件,我看了看我的checkpoint文件夹:
在这里插入图片描述
如图,根本没有.ckpt文件,除了一个checkpoint文件只有.meta.index.data...三种文件。

对于这种情况,读取、使用模型可以使用以下代码:

import tensorflow as tf

detection_graph = tf.Graph()
with tf.Session(graph=detection_graph) as sess:
    # 读取模型
    loader = tf.train.import_meta_graph('checkpoint/model-1700000.meta')
    loader.restore(sess, tf.train.latest_checkpoint('checkpoint/'))
	
	# 一些中间过程,比如生成、处理input_data等
	...
	
	# 使用模型
	input_tensor = detection_graph.get_tensor_by_name('input_name:0')
    output_tensor = detection_graph.get_tensor_by_name('output_name:0')
    
    generated_image = sess.run([geurated_image_tensor], feed_dict={input_tensor:input_data})

题外话,这几个文件作用是什么

引用https://www.cnblogs.com/mtcnn/p/9411711.html这篇文章:
【引用部分开始】
.meta文件以 “protocol buffer”格式保存了整个模型的结构图,模型上定义的操作等信息;.data-00000-of-00001文件和.index文件合在一起组成了ckpt文件,保存了网络结构中所有 权重和偏置的数值。.data文件保存的是变量值,.index文件保存的是.data文件中数据和.meta文件中结构图之间的对应关系;checkpoint是一个文本文件,记录了训练过程中在所有中间节点上保存的模型的名称,首行记录的是最后(最近)一次保存的模型名称。
【引用部分结束】


发布了36 篇原创文章 · 获赞 41 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/umbrellalalalala/article/details/88826085
今日推荐