2017-05-23 289 views
0

我目前正在嘗試學習如何使用TF-Slim,並且我正在遵循本教程:https://github.com/mnuke/tf-slim-mnistTensorflow Slim恢復模型和預測

假設我已經在檢查點中保存了訓練有素的模型,那麼現在如何使用該模型並應用它?就像在教程中,我該如何使用訓練有素的MNIST模型,並提供一套新的MNIST圖像,並打印預測結果?

回答

1

你可以嘗試像一個工作流程:

#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會話中,讓保護程序恢復會話中檢查點模型的所有變量。

相關問題