J'exécute le réseau cifar10 sur mon PC et après avoir terminé la formation et exécuté le script eval, l'erreur suivante apparaît:
2016-06-01 14:37:14.238317: precision @ 1 = 0.000
Traceback (most recent call last):
File "<ipython-input-1-adf2ca85bb77>", line 1, in <module>
runfile('/home/kang/Documents/work_code_PC1/py_tensorflow_learning/cifar10CNN_test/cifar10_eval_test.py', wdir='/home/kang/Documents/work_code_PC1/py_tensorflow_learning/cifar10CNN_test')
File "/usr/lib/python3/dist-packages/spyderlib/widgets/externalshell/sitecustomize.py", line 685, in runfile
execfile(filename, namespace)
File "/usr/lib/python3/dist-packages/spyderlib/widgets/externalshell/sitecustomize.py", line 85, in execfile
exec(compile(open(filename, 'rb').read(), filename, 'exec'), namespace)
File "/home/kang/Documents/work_code_PC1/py_tensorflow_learning/cifar10CNN_test/cifar10_eval_test.py", line 107, in <module>
tf.app.run()
File "/usr/local/lib/python3.4/dist-packages/tensorflow/python/platform/default/_app.py", line 30, in run
sys.exit(main(sys.argv))
File "/home/kang/Documents/work_code_PC1/py_tensorflow_learning/cifar10CNN_test/cifar10_eval_test.py", line 104, in main
evaluate()
File "/home/kang/Documents/work_code_PC1/py_tensorflow_learning/cifar10CNN_test/cifar10_eval_test.py", line 94, in evaluate
eval_once(saver, summary_writer, top_k_op, summary_op)
File "/home/kang/Documents/work_code_PC1/py_tensorflow_learning/cifar10CNN_test/cifar10_eval_test.py", line 72, in eval_once
coord.join(threads, stop_grace_period_secs = 10)
File "/usr/local/lib/python3.4/dist-packages/tensorflow/python/training/coordinator.py", line 264, in join
six.reraise(*self._exc_info_to_raise)
File "/usr/lib/python3/dist-packages/six.py", line 659, in reraise
raise value
File "/usr/local/lib/python3.4/dist-packages/tensorflow/python/training/queue_runner.py", line 185, in _run
sess.run(enqueue_op)
File "/usr/local/lib/python3.4/dist-packages/tensorflow/python/client/session.py", line 315, in run
return self._run(None, fetches, feed_dict)
File "/usr/local/lib/python3.4/dist-packages/tensorflow/python/client/session.py", line 473, in _run
raise RuntimeError('Attempted to use a closed Session.')
RuntimeError: Attempted to use a closed Session.
que signifie la session à huis clos? Les trains.py et eval.py doivent-ils fonctionner en même temps? Je suis nouveau dans tensorflow et me tape selon les codes de démonstration https://www.tensorflow.org/versions/r0.8/tutorials/deep_cnn/index.html
En regardant le code que vous avez publié , le problème se situe entre les lignes 50 et 51 dans eval_once()
:
with tf.Session() as sess:
ckpt = tf.train.get_checkpoint_state(FLAGS.checkpoint_dir)
if ckpt and ckpt.model_checkpoint_path:
saver.restore(sess, ckpt.model_checkpoint_path)
global_step = ckpt.model_checkpoint_path.split('/')[-1].split('-')[-1]
else:
print('No checkpoint file found')
return
# <<< The Session is closed here >>>
coord = tf.train.Coordinator()
try:
# ...
Lorsque le code quitte un bloc with tf.Session() as sess:
, sess
se ferme automatiquement et vous ne pouvez plus l'utiliser. Il existe (au moins) deux façons de résoudre ce problème:
Retrait des lignes 51 à 76 de 4 espaces, de sorte qu'elles se trouvent également à l'intérieur du bloc with
.
Créez la session sans utiliser un bloc with
et fermez-la manuellement:
def eval_once():
sess = tf.Session()
ckpt = tf.train.get_checkpoint_state(FLAGS.checkpoint_dir)
if ckpt and ckpt.model_checkpoint_path:
saver.restore(sess, ckpt.model_checkpoint_path)
global_step = ckpt.model_checkpoint_path.split('/')[-1].split('-')[-1]
else:
print('No checkpoint file found')
sess.close()
return
coord = tf.train.Coordinator()
try:
# ...
finally:
sess.close()