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

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

Asked on November 17, 2018 in Tensorflow.
Add Comment


  • 1 Answer(s)

    Here is an solution print a value of a tensor whenever the graph is evaluated by using run or eval function:

    # Initialize session
    import tensorflow as tf
    sess = tf.InteractiveSession()
     
    # Some tensor we want to print the value of
    a = tf.constant([1.0, 3.0])
     
    # Add print operation
    a = tf.Print(a, [a], message="This is a: ")
     
    # Add more elements of the graph using a
    b = tf.add(a, a)
    

    To evaluate the Whole graph use b.eval(), for example:

    I tensorflow/core/kernels/logging_ops.cc:79] This is a: [1 3]
    
    Answered on November 17, 2018.
    Add Comment


  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.