恢复张量流图的问题

时间:2017-09-10 22:06:53

标签: python tensorflow

我建立了一个带有张量流的神经网络,我在训练后保存了它,但是当我想要恢复它以进行预测时,它不起作用就是我得到的:

 2017-09-10 22:51:58.530272: W c:\tf_jenkins\home\workspace\release-
 win\m\windows\py\36\tensorflow\core\framework\op_kernel.cc:1158] Not found: 
 Key Variable_10 not found in checkpoint

 Key Variable_10 not found in checkpoint

我不知道问题出在哪里,这是我保存文件的地方:

   model_file = "C:/Users/ben-n_000/Desktop/travail 
   signal_courant/signal_courant_new/TensorFlow_model/model.ckpt"

我正确保存了模型

   saver = tf.train.Saver()
   saver.save(sess, model_file)

问题出现了:

    with tf.Session() as sess:
         sess.run(tf.global_variables_initializer())

         saver = tf.train.Saver()
         saver.restore(sess, model_file)

这令人非常沮丧,我无法理解这是什么问题,所以我需要你的帮助,thnaks。

1 个答案:

答案 0 :(得分:0)

我有2个函数train_network和make_prediction,用于保存模型并在make_prediction函数中重用它是如何工作的

     def train_neural_network(x):
       '''
       code here 
       ''' 
       #saver before innitalizing alla variables
       saver = tf.train.Saver()
       with tf.Session() as sess:
          sess.run(tf.global_variables_initializer())
          '''
          code here 
          '''


     def make_prediction(Z):
       '''
       code here 
       '''
       with tf.Session() as sess:
          sess.run(tf.global_variables_initializer())
          saver.restore(sess, model_file)
          '''
          code here 
          '''

并且在代码的末尾我们可以调用我们的函数并在调用make_prediction之前放置saver:

      train_neural_network(x)
      saver = tf.train.Saver()
      make_prediction(X_test[1])