我有 inception_resnet_v2_2016_08_30.ckpt 文件,这是一个预训练的起始模型。我想使用
saver.restore(sess, ckpt_filename)
但为此,我将需要编写训练该模型时使用的变量集。我在哪里可以找到这些(脚本或详细说明)?
请您参考如下方法:
首先,你已经在内存中获得了网络架构。您可以从 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})
