2016-11-18 7 views
0

Ich versuche zu lernen, wie man Modelle speichert und wiederherstellt. Mein Modell ist ein wenig zu kompliziert, so ist hier eine MWE, gerade von Befehlszeilen Python, die die gleichen Fehler produziert:Tensorflow speichern und laden

import tensorflow as tf 
v1 = tf.Variable(1, name="var1") 
init_op = tf.initialize_all_variables() 
saver = tf.train.Saver() 
with tf.Session() as sess: 
    sess.run(init_op) 
    save_path = saver.save(sess, "testchk.ckpt") 
    print "model saved" 

Dieses Format folgt die TensorFlow Dokumentation hier: https://www.tensorflow.org/versions/r0.11/api_docs/python/state_ops.html#Variable

Der Fehler I get is:

Traceback (most recent call last): 
    File "<stdin>", line 3, in <module> 
    File "/mnt/data/user/pkgs/enthought/canopy-1.5.1/lib/python2.7/site-packages/tensorflow/python/training/saver.py", line 1080, in save 
self.last_checkpoints, latest_filename) 
    File "/mnt/data/user/pkgs/enthought/canopy-1.5.1/lib/python2.7/site-packages/tensorflow/python/training/saver.py", line 632, in update_checkpoint_state 
    file_io.rename(temp_pathname, coord_checkpoint_filename, overwrite=True) 
    File "/mnt/data/user/pkgs/enthought/canopy-1.5.1/lib/python2.7/site-packages/tensorflow/python/lib/io/file_io.py", line 79, in rename 
compat.as_bytes(oldname), compat.as_bytes(newname), overwrite, status) 
    File "/opt/enthought/canopy-1.5.1/appdata/canopy-1.5.1.2730.rh5-x86_64/lib/python2.7/contextlib.py", line 24, in __exit__ 
self.gen.next() 
    File "/mnt/data/user/pkgs/enthought/canopy-1.5.1/lib/python2.7/site-packages/tensorflow/python/framework/errors.py", line 450, in raise_exception_on_not_ok_status 
    pywrap_tensorflow.TF_GetCode(status)) 
tensorflow.python.framework.errors.FailedPreconditionError: checkpoint.tmp.fe418ea583db4995810d23d4ca308e3a 

Wie kann ich diesen Fehler beheben?

+0

Sieht aus wie ein Dateisystemfehler, existiert der Pfad? Hat das Programm Schreibzugriff? – yuefengz

+0

Ist nicht standardmäßig nur das aktuelle Arbeitsverzeichnis vorhanden? Ja, es hat Schreibzugriff. – StatsSorceress

+0

Versuchen Sie einen absoluten Pfad zu verwenden? – yuefengz

Antwort

0

Okay, der absolute Pfad war nicht ganz die Antwort, aber hier ist, was funktioniert hat. Im Terminal:

mkdir test_checkpoint 
python 

Dann

import tensorflow as tf 
v1 = tf.Variable(1, name="var1") 
init_op = tf.initialize_all_variables() 
saver = tf.train.Saver() 
with tf.Session() as sess: 
    sess.run(init_op) 
    save_path = saver.save(sess, "./test_checkpoint/testchk.ckpt") 
    print "model saved" 

Es gibt eine Reihe von Dingen, dann druckt: model saved

Also ich denke, es funktioniert! Das Verzeichnis existierte schon vorher, also weiß ich nicht, warum es neu funktioniert hat, aber zumindest gibt es eine Lösung.

Verwandte Themen