sách gpt4 ăn đã đi

python - tensorflow cifar10_eval.py 错误 :RuntimeError: Attempted to use a closed Session. RuntimeError: Attempted to use a closed Session

In lại 作者:太空狗 更新时间:2023-10-29 18:24:11 33 4
mua khóa gpt4 giày nike

我在我的 PC 上运行 cifar10 网络,在完成训练和运行评估脚本后出现以下错误:

2016-06-01 14:37:14.238317: precision @ 1 = 0.000
Theo dõi (cuộc gọi gần đây nhất là cuộc gọi cuối cùng):

File "", line 1, in
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
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.

关闭 session 是什么意思? train.py 和 eval.py 应该同时运行吗?我是 tensorflow 的新手,根据演示代码自己输入 https://www.tensorflow.org/versions/r0.8/tutorials/deep_cnn/index.html

câu trả lời hay nhất

查看the code you posted ,问题出在 eval_once() 中的第 50 行和第 51 行之间:

với tf.Session() là 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]
khác:
print('No checkpoint file found')
trở lại
# <<< The Session is closed here >>>
coord = tf.train.Coordinator()
thử:
# ...

当代码退出 với tf.Session() là sess: block 时,phiên 会自动关闭,您不能再使用它。有(至少)两种方法可以解决此问题:

  1. 缩进 51 行 through 76 4 个空格,以便它们也在 với block 内。

  2. 在不使用 với block 的情况下创建 session 并手动关闭它:

    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]
    khác:
    print('No checkpoint file found')
    sess.close()
    trở lại

    coord = tf.train.Coordinator()
    thử:
    # ...
    Cuối cùng:
    sess.close()

关于python - tensorflow cifar10_eval.py 错误 :RuntimeError: Attempted to use a closed Session. RuntimeError: Attempted to use a closed Session,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37568980/

33 4 0
Chứng chỉ ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com
Xem sitemap của VNExpress