2017-02-28 4 views
1

TFRecordReaderからのrecord_stringのデコードにtensorflow parse_single_sequence_exampleを使用しています。 context_featuresとsequence_featuresの2つのdictsを返します。Tensorflowランタイム辞書検索、tf.parse_single_sequence_exampleからのhendling出力

filename_queue = tf.train.string_input_producer('temp.text', num_epochs=1, shuffle=True) 
reader = tf.TFRecordReader() 
key, record_string = reader.read(filename_queue) 
context_features={ 
    "output":tf.FixedLenFeature([],tf.int64) 
    } 
sequence_features={ 
    "input_sequence":tf.FixedLenSequenceFeature([5,],tf.float32) 
    } 
context_parsed, sequence_parsed = tf.parse_single_sequence_example(serialized=record_string,context_features=context_features,sequence_features=sequence_features) 

context_parsedとsequence_parsedは両方とも辞書です。キーに関連付けられたテンソルオブジェクトを取得するにはどうすればよいですか?次のフェッチ操作を行うと、

with tf.Session() as sess: 
    a=sess.run([context_parsed],feed_dict=None) 

これは失敗してしまいます。

Fetch argument {'output': <tf.Tensor 'ParseSingleSequenceExample/ParseSingleSequenceExample:1' shape=() dtype=int64>} of {'output': <tf.Tensor 'ParseSingleSequenceExample/ParseSingleSequenceExample:1' shape=() dtype=int64>} has invalid type <class 'dict'>, must be a string or Tensor. (Can not convert a dict into a Tensor or Operation.) 

context_parsed ['output']テンソルを取得するにはどうすればよいですか?私はどのようにテンソルを私のグラフのいくつかのプレースホルダーに供給しますか?

out=context_parsed['output'] 

上記の行を追加して取得しようとしましたが、動作しないため、端末がipythonに突き当たりました。

with tf.Session() as sess: 
    a=sess.run(out,feed_dict=None) 

Iはまたtf.contrib.learn.run_n

In [13]: context = tf.contrib.learn.run_n(context_parsed, n=1, feed_dict=None) 
In [14]: context[0] 
Out[14]: {'length': 6, 'output': 4} 
In [15]: context = tf.contrib.learn.run_n(out, n=1, feed_dict=None) 
--------------------------------------------------------------------------- 
TypeError         Traceback (most recent call last) 
<ipython-input-15-e5d7d977676f> in <module>() 

----> 1コンテキスト= tf.contrib.learn.run_n(うち、N = 1の出力を加算していfeed_dict =なし)

/home/ankgoyal/anaconda3/lib/python3.5/site- packages/tensorflow/contrib/learn/python/learn/graph_actions.py in run_n(output_dict, feed_dict, restore_checkpoint_path, n) 
    553  output_dict=output_dict, 
    554  feed_dicts=itertools.repeat(feed_dict, n), 
--> 555  restore_checkpoint_path=restore_checkpoint_path) 
    556 
    557 

/home/ankgoyal/anaconda3/lib/python3.5/site-packages/tensorflow/contrib/learn/python/learn/graph_actions.py in run_feeds(output_dict, feed_dicts, restore_checkpoint_path) 
    579  ValueError: if `output_dict` or `feed_dicts` is None or empty. 
    580 """ 
    --> 581 if not output_dict: 
    582  raise ValueError('output_dict is invalid: %s.' % output_dict) 
    583 if not feed_dicts: 

/home/ankgoyal/anaconda3/lib/python3.5/site-packages/tensorflow/python/framework/ops.py in __bool__(self) 
    513  `TypeError`. 
    514  """ 
--> 515  raise TypeError("Using a `tf.Tensor` as a Python `bool` is not allowed. " 
    516      "Use `if t is not None:` instead of `if t:` to test if a " 
    517      "tensor is defined, and use the logical TensorFlow ops " 

TypeError: Using a `tf.Tensor` as a Python `bool` is not allowed. Use `if t is not None:` instead of `if t:` to test if a tensor is defined, and use the logical TensorFlow ops to test the value of a tensor. 

にはどうすればcontext_parsed [ '出力']テンソルを取得するのですか?私はどのようにテンソルを私のグラフのいくつかのプレースホルダーに供給しますか?

答えて

1

私がやっていた間違いを理解しました。実際には、私はTFReader()の新しいスレッドを開始しなかったため、ターミナルがハングアップします。

with tf.Session() as sess: 
    sess.run(tf.initialize_all_variables()) 
    coord = tf.train.Coordinator() 
    threads = tf.train.start_queue_runners(coord=coord) 
    print(sess.run(context_parsed['length'])) 
    coord.join(threads) 

出力が6

として印刷されます
関連する問題