我下载了一个名为 inception_resnet_v2_2016_08_30.ckpt 的 tensorflow 检查点模型。
我是否需要创建一个在创建此检查点时使用的图表(包含所有变量)?
我如何使用这个模型?
请您参考如下方法:
首先,你已经在内存中获得了网络架构。您可以从 here 获取网络架构
有了这个程序后,使用以下方法来使用模型:
from inception_resnet_v2 import inception_resnet_v2, inception_resnet_v2_arg_scope
height = 299
width = 299
channels = 3
X = tf.placeholder(tf.float32, shape=[None, height, width, channels])
with slim.arg_scope(inception_resnet_v2_arg_scope()):
logits, end_points = inception_resnet_v2(X, num_classes=1001,is_training=False)
这样你就拥有了内存中的所有网络,现在你可以使用 tf.train.saver 使用检查点文件 (ckpt) 初始化网络:
saver = tf.train.Saver()
sess = tf.Session()
saver.restore(sess, "/home/pramod/Downloads/inception_resnet_v2_2016_08_30.ckpt")
如果你想提取瓶子的特征,这很简单,比如你想从最后一层获取特征,那么你只需声明 predictions = end_points["Logits"] 如果你想要为其他中间层获取它,您可以从上面的程序 inception_resnet_v2.py 中获取这些名称
之后你可以调用:output = sess.run(predictions, feed_dict={X:batch_images})
