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