By default TensorFlow builds up a graph rather than executing operations immediately. If you'd like literal values, try tf.enable_eager_execution()
:
>>> import tensorflow as tf
>>> tf.enable_eager_execution()
>>> X = tf.constant([[[1,2,3],[3,4,5]],[[3,4,5],[5,6,7]]])
>>> Y = tf.constant([[[11]],[[12]]])
>>> dataset = tf.data.Dataset.from_tensor_slices((X, Y))
>>> for x, y in dataset:
... print(x, y)
...
tf.Tensor(
[[1 2 3]
[3 4 5]], shape=(2, 3), dtype=int32) tf.Tensor([[11]], shape=(1, 1), dtype=int32)
tf.Tensor(
[[3 4 5]
[5 6 7]], shape=(2, 3), dtype=int32) tf.Tensor([[12]], shape=(1, 1), dtype=int32)
Note that in TensorFlow 2.x tf.enable_eager_execution()
is the default behavior and the symbol doesn't exist; you can just take that line out.
When graph building in TensorFlow 1.x, you need to create a Session
and run the graph to get literal values:
>>> import tensorflow as tf
>>> X = tf.constant([[[1,2,3],[3,4,5]],[[3,4,5],[5,6,7]]])
>>> Y = tf.constant([[[11]],[[12]]])
>>> dataset = tf.data.Dataset.from_tensor_slices((X, Y))
>>> tensor = dataset.make_one_shot_iterator().get_next()
>>> with tf.Session() as session:
... print(session.run(tensor))
...
(array([[1, 2, 3],
[3, 4, 5]], dtype=int32), array([[11]], dtype=int32))