tensorflow cifar10_eval.py error:RuntimeError: Attempted to use a closed Session.RuntimeError: Attempted to use a closed Session

前端 未结 1 1546
我在风中等你
我在风中等你 2020-12-11 02:20

I\'m running the cifar10 network on my PC and after finishing the training and running eval script the following error appears:

2016-06-01 14:37:14.238317: p         


        
1条回答
  •  感情败类
    2020-12-11 02:43

    Looking at the code you posted, the problem is between lines 50 and 51 in 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:
        # ...
    

    When the code exits a with tf.Session() as sess: block, sess is automatically closed, and you cannot use it any more. There are (at least) two ways to fix this problem:

    1. Indent lines 51 through 76 by 4 spaces, so that they are also inside the with block.

    2. Create the session without using a with block and close it manually:

      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()
      

    0 讨论(0)
提交回复
热议问题