tensorflow 关于打印 Tensor 对象的具体值(python)

import tensorflow as tf
x = tf.Variable(3, name='x')
y = x * 5
print(y)

这个时候输出的是: Tensor("mul:0", shape=(), dtype=int32) ,并不是预料中的15,那么怎么输出15呢?如下:

import tensorflow as tf
import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
x = tf.Variable(3, name='x')
y = x * 5
sess = tf.InteractiveSession()
sess.run(tf.global_variables_initializer())

# Add print operation
#x = tf.Print(x, [x], message="This is x: ")

# Add more elements of the graph using a
#b = tf.add(x,x).eval()
print(x.eval())
print(y.eval())

转载于:https://www.cnblogs.com/junblog/p/10621059.html

你可能感兴趣的:(tensorflow 关于打印 Tensor 对象的具体值(python))