定義
Variables are the parameters of the algorithm and TensorFlow keeps track of how to change these to optimize the algorithm.
變量一般為算法的參數,tf將會通過改變這些參數來使得算法的結果最優
Placeholders are objects that allow you to feed in data of a specific type and shape and depend on the results of the computational graph, such as the expected outcome of a computation.
Placeholders are just holding the position for data to be fed into the graph
Placeholders 是一個對象,你可以 feed in 數據(任意指定的shape)。一般作為computational graph的輸入。
注意區別兩者:Variables的shape是不會變的因為是網絡的參數(W,b等),但是里面的值是會改變的。Placeholders的shape是可變的,主要取決于batch的大小,但是不會改變其內容
How to create a variable
創建一個變量主要分為兩步:
(1)聲明一個變量 (2)初始化變量:這一步一般是在全部變量都聲明完成,且將會launch computational graph的時候進行ji
有時候可能我們需要用一個變量對另一個變量賦值,或者是用到了前一個變量的結構,這時候需要先初始化一個變量
創建一個 placeholder
同樣分為:
(1)聲明:定義數據類型和shape?
? (2) 初始化:一般是用feed_dict傳入數據,注意這時候傳入的數據只接受numpy或者是py自帶的數據結構,不接受tensor作為輸入