eval的使用
eval()其實就是tf.Tensor的session.run()的另一種寫法,
- eval()也是啟動計算的一種方式。基于tensorflow基本原理,首先需要定義圖,然后計算圖,
其中計算圖的函數(shù)有常見的run()函數(shù),如sess.run(),eval()也是類似。 - eval()只能用于tf.tensor類對象,也就是有輸出的operaton。沒有輸出的operation,使用
session.run()
placeholder和feec_dict的使用
placeholder:TensorFlow中的placeholder就是一個占位符,它并沒有實際的值,只會分配必要的內(nèi)存,需要使用feed_dict傳遞數(shù)據(jù)
tf.placeholder(dtype, shape=None, name=None)
feed_dict:feed_dict是一個字典,鍵為占位符,值為要傳遞給該占位符的值
使用:
import tensorflow as tf
x = tf.placeholder(tf.string)
with tf.Session() as sess:
output = sess.run(x, feed_dict={x:"Hello world"})
print(output)