How to print the value of a Tensor object in TensorFlow?

前端 未结 21 1567
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-22 07:44

I have been using the introductory example of matrix multiplication in TensorFlow.

matrix1 = tf.constant([[3., 3.]])
matrix2 = tf.constant([[2.],[2.]])
produ         


        
21条回答
  •  既然无缘
    2020-11-22 07:51

    You can check the output of a TensorObject without running the graph in a session, by enabling eager execution.

    Simply add the following two lines of code: import tensorflow.contrib.eager as tfe tfe.enable_eager_execution()

    right after you import tensorflow.

    The output of print product in your example will now be: tf.Tensor([[ 12.]], shape=(1, 1), dtype=float32)

    Note that as of now (November 2017) you'll have to install a Tensorflow nightly build to enable eager execution. Pre-built wheels can be found here.

提交回复
热议问题