tensorflow常用類

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符合

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 我想把夜色 像喚孩子一樣 喚回家 我不想讓夜色 抓緊一個人的衣角 讓他越走越老 我也不想讓夜色 咬住一條河流 那些...
    甘肅子溪閱讀 320評論 4 4
  • 1.【從本篇文章/視頻中學(xué)到最重要的概念】 2.【我在本篇文章中學(xué)到怦然心動的單詞】 3.【在本篇文章中最喜歡的一...
    109強(qiáng)宇閱讀 245評論 3 1
  • 我不知道自己在寫什么,可能就是看到你們寫的,就突然想寫了吧,沒有主題,沒有內(nèi)容,只想安安靜靜的寫下去。 昨天晚上的...
    像我這樣孤單的人閱讀 218評論 0 2
  • 很想來一場說走就走的旅行 卻只能拘泥于那座寫字樓 千篇一律 日復(fù)一日 如果肉身不能遠(yuǎn)行 那就讓心靈踏上旅途 或讀書...
    李木只閱讀 404評論 0 2

友情鏈接更多精彩內(nèi)容