1. 程式人生 > >tensorflow框架學習(一)placeholder 與variable

tensorflow框架學習(一)placeholder 與variable

1. placeholder —佔位符

placeholder, 譯為佔位符,官方說法:”TensorFlow provides a placeholder operation that must be fed with data on execution.” 即必須在執行時feed值。
placeholder 例項通常用來為演算法的實際輸入值作佔位符。例如,在MNIST例子中,定義輸入和輸出:

x = tf.placeholder(tf.float32, [None, 784])
#表示成員型別float32, [None, 784]是tensor的shape, None表示第一維是任意數量,784表示第二維是784維
y_ = tf.placeholder(tf.float32, [None, 10])

2. variable —變數

W = tf.Variable(tf.zeros([784, 10]))
b = tf.Variable(tf.zeros([10]))