我目前正在尝试学习如何使用TF-Slim,我正在学习本教程:https://github.com/mnuke/tf-slim-mnist。
假设我已经在检查点保存了经过训练的模型,我现在如何使用该模型并应用它?就像在教程中一样,我如何使用训练有素的MNIST模型并输入一组新的MNIST图像,并打印预测?
答案 0 :(得分:3)
您可以尝试以下工作流程:
#obtain the checkpoint file
checkpoint_file= tf.train.latest_checkpoint("./log")
#Construct a model as such:
with slim.arg_scope(mobilenet_arg_scope(weight_decay=weight_decay)):
logits, end_points = mobilenet(images, num_classes = dataset.num_classes, is_training = True, width_multiplier=width_multiplier)
#Obtain the trainable variables and a saver
variables_to_restore = slim.get_variables_to_restore()
saver = tf.train.Saver(variables_to_restore)
#Proceed to create your training optimizer and predictions monitoring, summaries etc.
...
#Finally when you're about to train your model in a session, restore the checkpoint model to your graph first:
with tf.Session() as sess:
saver.restore(sess, checkpoint_file)
#...Continue your training
基本上,您必须获取要恢复的正确变量,并且这些变量必须具有与检查点模型中找到的名称相匹配的名称。然后,将要恢复的变量列表传递给Saver,然后在TF会话中,让saver从会话中的检查点模型中恢复所有变量。
答案 1 :(得分:1)
查看官方TF-Slim documentation和walkthrough