最近博主需要使用已經訓練好的模型,網上搜的教程幾乎全需要用到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})