【问题标题】:Error when reading TFRecords with tensorflow: tensorflow.python.framework.errors.NotFoundError: FetchOutputs node ParseSingleExample/Squeeze使用 tensorflow 读取 TFRecords 时出错:tensorflow.python.framework.errors.NotFoundError: FetchOutputs node ParseSingleExample/Squeeze
【发布时间】:2016-07-19 15:24:30
【问题描述】:

我真的是 tensorflow 的新手,我确定我在这里做错了什么。我的问题是,当我从文件中读取记录时,代码有时会起作用,但大多数时候会失败:

import tensorflow as tf
import numpy as np
import time

def readFrame(inQueue, reader):
  frameWidth = int(1920/16)+1
  frameHeight = int(1080/16)+1
  frameItemsCount = frameWidth*frameHeight

  _, serialized_frame = reader.read(inQueue)
  features = tf.parse_single_example(
      serialized_frame,
      features= {
        'x'        : tf.FixedLenFeature([frameItemsCount], tf.float32)
        , 'y'        : tf.FixedLenFeature([frameItemsCount], tf.float32)
        , 'direction': tf.FixedLenFeature([frameItemsCount], tf.float32)
        # , 'force'    : tf.FixedLenFeature([frameItemsCount], tf.float32)
        # , 'sad'      : tf.FixedLenFeature([frameItemsCount], tf.float32)
      })

  return features

# pretty much copy paste from fully_connected_reader.py
def main(_):
  with tf.Graph().as_default():
    inputFramesQueue = tf.train.string_input_producer(["tfrecords.out"], num_epochs=100)
    reader = tf.TFRecordReader()

    init_op = tf.initialize_all_variables()
    sess = tf.Session()
    sess.run(init_op)
    coord = tf.train.Coordinator()
    threads = tf.train.start_queue_runners(sess=sess, coord=coord)

    try:
      step = 0
      while not coord.should_stop() and step < 3:
        start_time = time.time()
        frameDict = readFrame(inputFramesQueue, reader)
        print(frameDict)
        frame = sess.run([
          frameDict['x']
          , frameDict['y']
          , frameDict['direction'] 
          # , frameDict['force'] 
          # , frameDict['sad']
        ])
        print(frame[2])

        duration = time.time() - start_time
        if step % 100 == 0: print('Step %d: (%.3f sec)' % (step, duration))
        step += 1
    except tf.errors.OutOfRangeError:
      print('Done training for %d epochs, %d steps.' % (FLAGS.num_epochs, step))
    finally:
      coord.request_stop()

    coord.join(threads)
    sess.close()

if __name__ == '__main__':
  tf.app.run()

例如,当我运行它时,我得到了两个不同的输出:

(venv) bash-3.2$ python src/readframes.py
{'x': <tf.Tensor 'ParseSingleExample/Squeeze_x:0' shape=(8228,) dtype=float32>, 'direction': <tf.Tensor 'ParseSingleExample/Squeeze_direction:0' shape=(
8228,) dtype=float32>, 'y': <tf.Tensor 'ParseSingleExample/Squeeze_y:0' shape=(8228,) dtype=float32>}
Traceback (most recent call last):
  File "/Users/mikaelle/Projects/Omat/tensorflow-grouping/venv/lib/python3.5/site-packages/tensorflow/python/client/session.py", line 715, in _do_call
    return fn(*args)
  File "/Users/mikaelle/Projects/Omat/tensorflow-grouping/venv/lib/python3.5/site-packages/tensorflow/python/client/session.py", line 697, in _run_fn
    status, run_metadata)
  File "/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/contextlib.py", line 66, in __exit__
    next(self.gen)
  File "/Users/mikaelle/Projects/Omat/tensorflow-grouping/venv/lib/python3.5/site-packages/tensorflow/python/framework/errors.py", line 450, in raise_ex
ception_on_not_ok_status
    pywrap_tensorflow.TF_GetCode(status))
tensorflow.python.framework.errors.NotFoundError: FetchOutputs node ParseSingleExample/Squeeze_y:0: not found

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "src/readframes.py", line 62, in <module>
    tf.app.run()
  File "/Users/mikaelle/Projects/Omat/tensorflow-grouping/venv/lib/python3.5/site-packages/tensorflow/python/platform/app.py", line 30, in run
    sys.exit(main(sys.argv))
  File "src/readframes.py", line 44, in main
    , frameDict['direction']
  File "/Users/mikaelle/Projects/Omat/tensorflow-grouping/venv/lib/python3.5/site-packages/tensorflow/python/client/session.py", line 372, in run
    run_metadata_ptr)
  File "/Users/mikaelle/Projects/Omat/tensorflow-grouping/venv/lib/python3.5/site-packages/tensorflow/python/client/session.py", line 636, in _run
    feed_dict_string, options, run_metadata)
  File "/Users/mikaelle/Projects/Omat/tensorflow-grouping/venv/lib/python3.5/site-packages/tensorflow/python/client/session.py", line 708, in _do_run
    target_list, options, run_metadata)
  File "/Users/mikaelle/Projects/Omat/tensorflow-grouping/venv/lib/python3.5/site-packages/tensorflow/python/client/session.py", line 728, in _do_call
    raise type(e)(node_def, op, message)
tensorflow.python.framework.errors.NotFoundError: FetchOutputs node ParseSingleExample/Squeeze_y:0: not found
(venv) bash-3.2$

(venv) bash-3.2$ python src/readframes.py
{'y': <tf.Tensor 'ParseSingleExample/Squeeze_y:0' shape=(8228,) dtype=float32>, 'direction': <tf.Tensor 'ParseSingleExample/Squeeze_direction:0' shape=(
8228,) dtype=float32>, 'x': <tf.Tensor 'ParseSingleExample/Squeeze_x:0' shape=(8228,) dtype=float32>}
[ 0.  0.  0. ...,  0.  0.  0.]
Step 0: (0.014 sec)
{'y': <tf.Tensor 'ParseSingleExample_1/Squeeze_y:0' shape=(8228,) dtype=float32>, 'direction': <tf.Tensor 'ParseSingleExample_1/Squeeze_direction:0' sha
pe=(8228,) dtype=float32>, 'x': <tf.Tensor 'ParseSingleExample_1/Squeeze_x:0' shape=(8228,) dtype=float32>}
[ 0.  0.  0. ...,  0.  0.  0.]
{'y': <tf.Tensor 'ParseSingleExample_2/Squeeze_y:0' shape=(8228,) dtype=float32>, 'direction': <tf.Tensor 'ParseSingleExample_2/Squeeze_direction:0' sha
pe=(8228,) dtype=float32>, 'x': <tf.Tensor 'ParseSingleExample_2/Squeeze_x:0' shape=(8228,) dtype=float32>}
[ 0.          2.24240255  2.24240255 ...,  0.          0.          0.        ]
(venv) bash-3.2$

当试图从那里获取项目时,似乎无法访问文件...

【问题讨论】:

    标签: python python-3.x tensorflow


    【解决方案1】:

    我通过在启动线程后和开始读取记录之前休眠一段时间来消除该错误。

    threads = tf.train.start_queue_runners(sess=sess, coord=coord)
    time.sleep(1)
    

    如果我在启动线程之前添加了睡眠,它没有效果......我对正在发生的事情的最佳猜测是可能有一些预读缓冲区被队列线程填充,但解析数据并没有等待buffer 在开始读取之前有足够的数据...

    我仍然认为我在这里做错了什么。即使在添加睡眠之后,我似乎也无法比提供服务的速度更快地读取数据。

    【讨论】:

      猜你喜欢
      • 2018-02-11
      • 1970-01-01
      • 2018-06-14
      • 2016-09-06
      • 2018-12-25
      • 1970-01-01
      • 2020-09-14
      • 2018-02-10
      • 1970-01-01
      相关资源
      最近更新 更多