Search code examples
tensorflowskflow

How to see values inside tensor while using skflow


I've checked How to print the value of a Tensor object in TensorFlow?. However doesn't seem to be working out of the box with skflow. E.g. tried like this :

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

Also tried

sess = tf.InteractiveSession()

before calling word_vectors.eval(). But all this leads to crash:

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

Does anybody know relatively easy way to look at content of Tensors created by skflow ?


Solution

  • It is not clear what error you are throwing but I got the error "Attempting to use uninitialized value words/words_embeddings". Initializing the variables fixed the error.

    So the working code was:

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

    I have also moved the graph node word_vectors outside of the session context though that wasn't necessary to fix the error.