1. tf.split(3, group, input) # 拆分函數
3 表示的是在第三個維度上, group表示拆分的次數, input 表示輸入的值less
import tensorflow as tf import numpy as np x = [[1, 2], [3, 4]] Y = tf.split(axis=1, num_or_size_splits=2, value=x) sess = tf.Session() for y in Y: print(sess.run(y))
2. tf.concat(3, input) # 串接函數
3 表示的是在第三個維度上, input表示的是輸入,輸入通常都是列表dom
import tensorflow as tf x = [[1, 2], [3, 4]] y = tf.concat(x, axis=0) sess = tf.Session() print(sess.run(y))
3. tf.squeeze(input, squeeze_dims=[1, 2]) # 表示的是去除列數爲1的維度, squeeze_dim 指定維度函數
import tensorflow as tf import numpy as np x = [[1, 2]] print(np.array(x).shape) y = tf.squeeze(x, axis=[0]) sess = tf.Session() print(sess.run(y))
4. tf.less_equal(a, b) a 能夠是一個列表, b表示須要比較的數,若是比b大返回false,否者返回Truespa
import tensorflow as tf import numpy as np raw_gt = [1, 2, 3, 4] y = tf.where(tf.less_equal(raw_gt, 2)) sess = tf.Session() print(sess.run(y))
5.tf.where(input) # 返回是真的序號,經過tf.where找出小於等於2的數的序號code
import tensorflow as tf import numpy as np raw_gt = [1, 2, 3, 4] y = tf.where(tf.less_equal(raw_gt, 2)) sess = tf.Session() print(sess.run(y))
6. tf.gather # 根據序列號對數據進行取值,輸入的是input, indexorm
import tensorflow as tf import numpy as np raw_gt = [3, 4, 5, 6] y = tf.gather(raw_gt, [[0], [1]]) sess = tf.Session() print(sess.run(y))
7. tf.cast(input, tf.float32) # 主要目的是進行數值類型轉換blog
import tensorflow as tf import numpy as np raw_gt = [3.0, 4.0, 5.0, 6.0] y = tf.cast(raw_gt, tf.int32) sess = tf.Session() print(sess.run(y))
8. tf.expand_dims(input, axis=1) # 進行矩陣維度的擴增input
import tensorflow as tf import numpy as np raw_gt = [3.0, 4.0, 5.0, 6.0] y = tf.expand_dims(raw_gt, axis=1) sess = tf.Session() print(sess.run(tf.shape(y)))
9. tf.argmax(input, axis=1) 根據維度找出這個維度下的最大值的序號, axis=0 表示找出每一行中的最大值, axis=1,表示找出每一列的最大值it
import tensorflow as tf import numpy as np raw_gt = [[3.0, 4.0], [5.0, 3]] y = tf.argmax(raw_gt, axis=1) sess = tf.Session() print(sess.run(y))
1o. tf.reshape(input, shape) # tf.reshape主要用於數據的shape從新組合io
import tensorflow as tf import numpy as np a = [[1, 2], [3, 4]] y = tf.reshape(a, [-1, 4]) sess = tf.Session() print(sess.run(y))
11. tf.stack(input, axis) # 進行數據的拼接,爲了去除一個維度
import tensorflow as tf distort_left_right_random = tf.random_uniform([1], 0, 1.0, dtype=tf.float32)[0] mirror = tf.less(tf.stack([1.0, 0.8, 1.0]), 0.5) sess = tf.Session() print(sess.run(mirror)) mirror = tf.boolean_mask([0, 1, 2], mirror) sess = tf.Session() print(sess.run(mirror))
12.tf.less(a, b) # 若是a小於b返回True
13.tf.boolean_mask # 找出數據中是True的位置
mirror = tf.boolean_mask([0, 1, 2], [True, False, False]) sess = tf.Session() print(sess.run(mirror))
13 tf.slice # 根據給出的起始位置進行數據的抽取
# tf.slice # import tensorflow as tf # import numpy as np # x=[[1,2,3],[4,5,6]] # y=np.arange(24).reshape([2,3,4]) # z=tf.constant([[[1,2,3],[4,5,6]], [[7,8,9],[10,11,12]], [[13,14,15],[16,17,18]]]) # sess=tf.Session() # begin_x=[1,0] #第一個1,決定了從x的第二行[4,5,6]開始,第二個0,決定了從[4,5,6] 中的4開始抽取 # size_x=[1,2] # 第一個1決定了,從第二行以起始位置抽取1行,也就是隻抽取[4,5,6] 這一行,在這一行中從4開始抽取2個元素 # out=tf.slice(x,begin_x,size_x) # print(sess.run(out))
14 .tf.reduce_sum(input) 表示將全部的進行相加
15 .tf.gfile.MakeDirs(train_dir) # 根據train_dir建立文件夾
import tensorflow as tf train_dir = 'make/' tf.gfile.MakeDirs(train_dir)
16. tf.gfile.IsDirectory(train_dir) # 判斷是不是文件夾
if tf.gfile.IsDirectory(train_dir): print('1') else: print('0')
17.tf.transpose(input, [1, 0]) # 表示將第一維的大小與第二維度進行調換
import tensorflow as tf import numpy as np x = [[1, 2, 3, 4], [1, 2, 4, 3]] print(np.shape(x)) sess = tf.Session() # 進行維度的變化,perm表示將第一二維度轉換爲第一個維度 print(sess.run(tf.transpose(x, perm=[1, 0])))