About Python print and Tensorflow tutorials
I am doing MNIST at the beginning of the Tensor flow tutorial.
Among them, I would like to see the contents of x, y, weight and bias b, W.
That's why
>>print x,y,b,W
running
Tensor("Placeholder:0", shape=TensorShape([Dimension(None), Dimension(784)], dtype=float32)
Tensor("Softmax:0", shape=TensorShape([Dimension(None), Dimension(10)], dtype=float32)
<tensorflow.python.ops.variables.Variable object at 0x1006b0b90>
<tensorflow.python.ops.variables.Variable object at 0x101b76410>
appears.
Weight and bias have actual values, right?
Is there any way to display them?
Please let me know.
python tensorflow
The sensorflow variable refers to the operation of tensorflow
during the session rather than to the so-called variable. First, x
is represented by sess.run(train_step, feed_dict={x:batch_xs,y_:batch_ys})
entered in the session.Since it represents an operation that passes values of b
and W
within a code> session, if you let the session evaluate this operation, it can be displayed as follows.
print sess.run(W)
print sess.run(b)
For interactive shells such as ipython, tf.InteractiveSession is recommended.
The following is the result of running the example in the tensorflow document at hand:
In[1]:import tensorflow as tf
In[2]: sess=tf.InteractiveSession()
In[3]: a=tf.constant(5.0)
In[4]: b=tf.constant(6.0)
In[5]: c=a*b
In[6]: print(c.eval())
30.0
In[7]—sess.close()
You can also see the values of variables as a.eval() or b.eval().
© 2024 OneMinuteCode. All rights reserved.