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())


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM