1 tf.Variable.__init__(initial_value, ????????trainable=True, collections=None, ????????validate_shape=True, name=None)
initial_value: A Tensor, or Python object convertible to aTensor.The initial value for the Variable。這里的初始值可以是數(shù)組,常量,以及隨機(jī)出來的tensor.
trainable: If True, the default, also adds the variable to the the graph collection GraphKeys.TRAINABLE_VARIABLES. This collection is used as the default list of variables to use by the Optimizerclasses.
collections: List of graph collections keys. The new variable is added to these collections. Defaults to [GraphKeys.VARIABLES](默認(rèn)值)
validate_shape(驗(yàn)證形狀): If False, allows the variable to be initialized with a value of unknown shape. If True, the default, the shape of initial_value must be known.
name: Optional name for the variable. Defaults to' Variable' and gets uniquified automatically.
Returns:
?A Variable
2 tensorflow的主要數(shù)據(jù)類型
<1>tensor?
tf.constant(value, dtype=None, shape=None, name='Const');
? ? ? ? 這個類型是tensorflow 中最常用的數(shù)據(jù)類型,他并不儲存實(shí)際數(shù)值,但是保存了包括初始值,形狀,名字等一系列信息,相當(dāng)于與一個指針,先用這個指針構(gòu)建出完整的Graph,在把指針指向具體的對象實(shí)現(xiàn)真實(shí)的計(jì)算,這只是一個形象的比喻。
<2>variable
tf.Variable(initial_value, trainable=True, collections=None,? ? ? ? ????????????????????????????????validate_shape=True, name=None)
---initial_value: a tensor
tf.get_variable(name, shape=None, dtype=tf.float32, initializer=None, trainable=True, collections=None)
---配合tf.variable_scope(name,reuse = False),有兩種用法
? ? ? 這個類型用來定義需要進(jìn)行學(xué)習(xí)的參數(shù),ex.weights,bias等,會自動執(zhí)行梯度下降。
<3>palceholder
tf.placeholder(dtype, shape=None, name=None)
?這個類型主要是用于數(shù)據(jù)的輸入,相當(dāng)于占位符,為Graph圖中預(yù)先留下數(shù)據(jù)的入口。
函數(shù):
在例如tf.matmul()的計(jì)算函數(shù)中,variable,tensor按照同一種數(shù)據(jù),也就是說,可以理解為variable屬于tensor,在tensorflow框架中任意計(jì)算,只要shape符合