簡單函式不給用例
函式原型
def moments(
x,axes,
shift=none, # pylint: disable=unused-argument
name=none,
keep_dims=false):
例子
img = tf.variable(tf.random_normal([2,3,4]))
#keep_dims設定為true表示axes這個引數維度為1,其他維度和原來保持一樣
#當為false,表示axes這個維度直接消失,維度減一。
mean, variance = tf.nn.moments(img, [-1], keep_dims=true)
mean1, variance1 = tf.nn.moments(img, [-1])
列印mean和mean1結果:
[[[-0.01752006]
[-0.3934618 ]
[ 0.5831194 ]]
[[-0.40659836]
[ 0.26763207]
[-0.7876693 ]]]
[[-0.01752006 -0.3934618 0.5831194 ]
[-0.40659836 0.26763207 -0.7876693 ]]
可以看出mean變成(2,3,1),而mean1為(2,3)
函式原型
def concat(values, axis, name="concat"):
values值是以tuple形式傳入,兩個需要進行concat的matrix,axis指示按什麼維度concat
原型
def embedding_lookup(
params,
ids,
partition_strategy="mod",
name=none,
validate_indices=true, # pylint: disable=unused-argument
max_norm=none):
實現功能,從params中抽取ids號的vector組成乙個matrix。
ids = tf.variable(tf.ones([3], dtype=tf.int32))
lookup_table = tf.variable(tf.random_normal([2,3], dtype=tf.float32))
outputs = tf.nn.embedding_lookup(lookup_table, ids)
列印lookup_table和outputs:
[[ 0.82692766 -0.6102561 0.36227643]
[-0.06371575 1.1494356 -0.27827913]]
[[-0.06371575 1.1494356 -0.27827913]
[-0.06371575 1.1494356 -0.27827913]
[-0.06371575 1.1494356 -0.27827913]]
可以看到outputs中,取了3次lookup_table[1]組成matrix
函式原型
def tile(input, multiples, name=none):
功能實現,對matrix的複製,inputs是要複製的,multiples是規則,為乙個list,表示要複製的維度和次數,且multi的維度應等於inputs。
t = tf.constant([[[1, 1, 1],
[2, 2, 2]],
[[3, 3, 3],
[4, 4, 4]],
[[5, 5, 5],
[6, 6, 6]]])
b = tf.slice(t, [1, 0, 0], [2, 1, 2]) # tf.slice(要被slice的tensor, 開始的索引位置, 對應維度slice多少個)
結果:[[[3 3]]
[[5 5]]]
# 實現根據indices查詢tensor的值
# tf.gather_nd(tensor, indices, name=none)
t = tf.constant([[[1, 1, 1],
[2, 2, 2]],
[[3, 3, 3],
[4, 9, 4]],
[[5, 5, 5],
[6, 6, 7]]])
b = tf.gather_nd(t, [[1,1,1],[2,1,2]]) # tf.gather_nd(要進行查詢的tensor, 查詢的索引位置)
結果:
[9 7]
功能1、 tf.where(tensor),返回tensor種true所在的索引
功能2、 tf.where(tensor, a,b),將a,b,tensor的維度要一樣,tensor種true的索引位置取a,false位置取b
這是乙個很靈活的函式,可以和tf.equal函式使用;也可以和上面的tf.gather_nd + tf.equal配合使用用處完全不同
1. 與tf.equal:
y1 = [[0.0, 0.0, 1.0, 0.0, 1.0],[0.0, 1.0, 0.0, 1.0, 0.0]]
y2 = [[0.0, 0.0, 4.0, 0.0, 4.0],
[0.0, 4.0, 0.0, 4.0, 0.0]]
b = tf.where(tf.equal(y1, 1.0), y2, y1)結果:
[[0. 0. 4. 0. 4.]
[0. 4. 0. 4. 0.]]
2. 與tf.gather_nd:
y1 = [[0.0, 0.0, 1.0, 0.0, 1.0],[0.0, 1.0, 0.0, 1.0, 0.0]]
y2 = [[0.0, 0.0, 4.0, 0.0, 4.0],
[0.0, 4.0, 0.0, 4.0, 0.0]]
t = tf.gather_nd(y2, tf.where(tf.equal(y1, 1.0)))結果:
[4. 4. 4. 4.]
仔細對比#
tensorflow中一些重要函式
請參考這裡 tf.nn.conv2d input,filter,strides,padding,use cudnn on gpu none,name none 除去name引數用以指定該操作的name,與方法有關的一共五個引數 第乙個引數input 指需要做卷積的輸入影象,它要求是乙個tensor,...
tensorflow一些常用知識
value是賦值,可以是乙個數,也可以是乙個list.dtype指定數字型別,比如tf.float32 shape指定器形狀 維度 如果value是乙個常數,則這個常量中所有值都按這個值來賦值。如果value是list,那麼len value 一定要小於等於shape展開後的長度。賦值時,先將val...
PS中一些常用知識
1,前景色,背景色什麼意思 你開啟ps後有個工具欄,在那一大堆工具下面有前後疊著的兩個方塊,置前的是前景色置後的是背景色,二者可以相互轉換。在一般的使用中,前景色和背景色其實只是乙個概念性的問題,並不是說就代表著 的顏色。簡單點說就是你畫 了乙個矩形框,想填充紅色。這時你可以選擇把前景色設為紅色,然...