如何在使用 skflow 时查看张量内的值
How to see values inside tensor while using skflow
我检查过 。然而,似乎并没有与 skflow 开箱即用。
例如。像这样尝试过:
with tf.Session():
word_vectors = skflow.ops.categorical_variable(X_test[0], n_classes=n_words,embedding_size=EMBEDDING_SIZE, name='words')
word_vectors.eval()
也尝试过
sess = tf.InteractiveSession()
在调用 word_vectors.eval() 之前。但这一切都会导致崩溃:
Traceback (most recent call last):
File "/Users/mypc/Documents/scripts/scikitflow/small_rnn_test/test_load.py", line 32, in <module>
word_vectors.eval()
File "/Library/Python/2.7/site-packages/tensorflow/python/framework/ops.py", line 405, in eval
return _eval_using_default_session(self, feed_dict, self.graph, session)
File "/Library/Python/2.7/site-packages/tensorflow/python/framework/ops.py", line 2728, in _eval_using_default_session
return session.run(tensors, feed_dict)
File "/Library/Python/2.7/site-packages/tensorflow/python/client/session.py", line 345, in run
results = self._do_run(target_list, unique_fetch_targets, feed_dict_string)
File "/Library/Python/2.7/site-packages/tensorflow/python/client/session.py", line 419, in _do_run
e.code)
tensorflow.python.framework.errors.FailedPreconditionError: Attempting to use uninitialized value words/words_embeddings
[[Node: words/embedding_lookup/embedding_lookup = Gather[Tindices=DT_INT64, Tparams=DT_FLOAT, _device="/job:localhost/replica:0/task:0/cpu:0"](words/words_embeddings, words/embedding_lookup/Reshape)]]
Caused by op u'words/embedding_lookup/embedding_lookup', defined at:
File "/Users/mypc/Documents/scripts/scikitflow/small_rnn_test/test_load.py", line 31, in <module>
word_vectors = skflow.ops.categorical_variable(X_test[0], n_classes=n_words,embedding_size=EMBEDDING_SIZE, name='words')
File "/Library/Python/2.7/site-packages/skflow/ops/embeddings_ops.py", line 77, in categorical_variable
return embedding_lookup(embeddings, tensor_in)
File "/Library/Python/2.7/site-packages/skflow/ops/embeddings_ops.py", line 50, in embedding_lookup
embeds_flat = tf.nn.embedding_lookup(params, ids_flat, name)
File "/Library/Python/2.7/site-packages/tensorflow/python/ops/embedding_ops.py", line 46, in embedding_lookup
return array_ops.gather(params[0], ids, name=name)
File "/Library/Python/2.7/site-packages/tensorflow/python/ops/gen_array_ops.py", line 302, in gather
name=name)
File "/Library/Python/2.7/site-packages/tensorflow/python/ops/op_def_library.py", line 633, in apply_op
op_def=op_def)
File "/Library/Python/2.7/site-packages/tensorflow/python/framework/ops.py", line 1710, in create_op
original_op=self._default_original_op, op_def=op_def)
File "/Library/Python/2.7/site-packages/tensorflow/python/framework/ops.py", line 988, in __init__
self._traceback = _extract_stack()
有人知道查看由 skflow 创建的张量内容的相对简单的方法吗?
不清楚你抛出的是什么错误,但我收到了错误 "Attempting to use uninitialized value words/words_embeddings"。初始化变量修复了错误。
所以工作代码是:
word_vectors = skflow.ops.categorical_variable([1,2], n_classes=3,embedding_size=2, name='words')
with tf.Session() as sess:
tf.initialize_all_variables().run()
word_vectors.eval()
我也将图形节点 word_vectors
移到了会话上下文之外,尽管这不是修复错误所必需的。
categorical_variable
不会为您初始化所有变量。它不像初始化会话、变量、图形等的估计器。此时,如果您使用 tf.initialize_all_variables().run()
,您将能够获得那些值。另外请注意,您可以通过估计器的 bias_
和 weights_
属性访问权重和偏差。
我检查过
with tf.Session():
word_vectors = skflow.ops.categorical_variable(X_test[0], n_classes=n_words,embedding_size=EMBEDDING_SIZE, name='words')
word_vectors.eval()
也尝试过
sess = tf.InteractiveSession()
在调用 word_vectors.eval() 之前。但这一切都会导致崩溃:
Traceback (most recent call last):
File "/Users/mypc/Documents/scripts/scikitflow/small_rnn_test/test_load.py", line 32, in <module>
word_vectors.eval()
File "/Library/Python/2.7/site-packages/tensorflow/python/framework/ops.py", line 405, in eval
return _eval_using_default_session(self, feed_dict, self.graph, session)
File "/Library/Python/2.7/site-packages/tensorflow/python/framework/ops.py", line 2728, in _eval_using_default_session
return session.run(tensors, feed_dict)
File "/Library/Python/2.7/site-packages/tensorflow/python/client/session.py", line 345, in run
results = self._do_run(target_list, unique_fetch_targets, feed_dict_string)
File "/Library/Python/2.7/site-packages/tensorflow/python/client/session.py", line 419, in _do_run
e.code)
tensorflow.python.framework.errors.FailedPreconditionError: Attempting to use uninitialized value words/words_embeddings
[[Node: words/embedding_lookup/embedding_lookup = Gather[Tindices=DT_INT64, Tparams=DT_FLOAT, _device="/job:localhost/replica:0/task:0/cpu:0"](words/words_embeddings, words/embedding_lookup/Reshape)]]
Caused by op u'words/embedding_lookup/embedding_lookup', defined at:
File "/Users/mypc/Documents/scripts/scikitflow/small_rnn_test/test_load.py", line 31, in <module>
word_vectors = skflow.ops.categorical_variable(X_test[0], n_classes=n_words,embedding_size=EMBEDDING_SIZE, name='words')
File "/Library/Python/2.7/site-packages/skflow/ops/embeddings_ops.py", line 77, in categorical_variable
return embedding_lookup(embeddings, tensor_in)
File "/Library/Python/2.7/site-packages/skflow/ops/embeddings_ops.py", line 50, in embedding_lookup
embeds_flat = tf.nn.embedding_lookup(params, ids_flat, name)
File "/Library/Python/2.7/site-packages/tensorflow/python/ops/embedding_ops.py", line 46, in embedding_lookup
return array_ops.gather(params[0], ids, name=name)
File "/Library/Python/2.7/site-packages/tensorflow/python/ops/gen_array_ops.py", line 302, in gather
name=name)
File "/Library/Python/2.7/site-packages/tensorflow/python/ops/op_def_library.py", line 633, in apply_op
op_def=op_def)
File "/Library/Python/2.7/site-packages/tensorflow/python/framework/ops.py", line 1710, in create_op
original_op=self._default_original_op, op_def=op_def)
File "/Library/Python/2.7/site-packages/tensorflow/python/framework/ops.py", line 988, in __init__
self._traceback = _extract_stack()
有人知道查看由 skflow 创建的张量内容的相对简单的方法吗?
不清楚你抛出的是什么错误,但我收到了错误 "Attempting to use uninitialized value words/words_embeddings"。初始化变量修复了错误。
所以工作代码是:
word_vectors = skflow.ops.categorical_variable([1,2], n_classes=3,embedding_size=2, name='words')
with tf.Session() as sess:
tf.initialize_all_variables().run()
word_vectors.eval()
我也将图形节点 word_vectors
移到了会话上下文之外,尽管这不是修复错误所必需的。
categorical_variable
不会为您初始化所有变量。它不像初始化会话、变量、图形等的估计器。此时,如果您使用 tf.initialize_all_variables().run()
,您将能够获得那些值。另外请注意,您可以通过估计器的 bias_
和 weights_
属性访问权重和偏差。