2016-12-29 17 views
2

私は "カーネルが死んでしまったようだ"か、エラーが出る( "Variable ... already exits")テンソルフローモデルを保存/復元するのに苦労します。私のカーネルが死ぬTensorflow saver:カーネルが死んでいるようです

が、私は私のコンソールにこのエラーログを取得し、次のよう

[I 21:13:41.505 NotebookApp] Saving file at /Nanodegree_MachineLearning/06_Capstone/capstone.ipynb 
terminate called after throwing an instance of 'std::bad_alloc' 
    what(): std::bad_alloc 
[I 21:17:05.416 NotebookApp] KernelRestarter: restarting kernel (1/5) 
WARNING:root:kernel 81679b46-ec9b-4ce6-b5be-ae2d9cf01210 restarted 
[I 21:17:41.778 NotebookApp] Saving file at /Nanodegree_MachineLearning/06_Capstone/capstone.ipynb 
[19324:20881:1229/212110:ERROR:object_proxy.cc(583)] Failed to call method: org.freedesktop.UPower.GetDisplayDevice: object_path= /org/freedesktop/UPower: org.freedesktop.DBus.Error.UnknownMethod: Method "GetDisplayDevice" with signature "" on interface "org.freedesktop.UPower" doesn't exist 

私のコードは次のとおりです。

if __name__ == '__main__': 
    if LEARN_MODUS: 
     with tf.Session() as sess: 
      sess.run(tf.global_variables_initializer()) 
      steps_per_epoch = len(X_train) // BATCH_SIZE 
      num_examples = steps_per_epoch * BATCH_SIZE 

      # Train model 
      for i in range(EPOCHS): 
       for step in range(steps_per_epoch): 
        #Calculate next Batch 
        batch_start = step * BATCH_SIZE 
        batch_end = (step + 1) * BATCH_SIZE 
        batch_x = X_train[batch_start:batch_end] 
        batch_y = y_train[batch_start:batch_end] 

        #Run Training 
        loss = sess.run(train_op, feed_dict={x: batch_x, y: batch_y, keep_prob: 0.5}) 

      try: 
       saver 
      except NameError: 
       saver = tf.train.Saver() 
      saver.save(sess, 'foo') 
      print("Model saved") 

モデルを復元するには、私が使用します。

predicions = tf.argmax(fc2,1) 
predicted_classes = [] 

try: 
    saver 
except NameError: 
    saver = tf.train.Saver() 

with tf.Session() as sess: 
    saver = tf.train.import_meta_graph('foo.meta') 
    saver.restore(sess, tf.train.latest_checkpoint('./')) 

    predicted_classes = sess.run(predicions, feed_dict={x: X_test, keep_prob: 1.0}) 

私はいろいろな方法で試しましたが、ときどき動作しますが(常にそうではありません!)、ときどきクラッシュし、いつか変数エラー。他の方法で保存/復元を使用する必要がありますか?

私が使用しています: のUbuntu 14.04 アナコンダ3 をjupyterノートパソコン内部のPython 3.5.2 Tensorflowは0.12

ありがとうございました!

答えて

3

これは、メモリが不足しているときに発生する可能性があります。解決策は、より小さなバッチサイズを試すことです。テストセットを1つのrun呼び出しに渡していることがわかります。すべての例を一度に実行するのに十分なメモリが必要です。 eval_in_batchesのようにいくつかの小規模な実行呼び出しで精度を集計することができます

+0

ありがとうございました。 :-) – Weedjo

関連する問題