目錄
方法概要
- from numpy , list 從numpy創建,或者直接喂list
- zeros, ones
- fill
- random
- constant
- Application
From Numpy , List
喂list必須是要tensor能夠支持的格式,如果喂 [ 1, ( 2, 3 ) ] 這樣的機會報錯。
tf.zeros
注意 tf.convert_to_tensor 與 直接創建的區別:
tf.convert_to_tensor([2,3]) #是接收value,Out[16]: <tf.Tensor: id=103, shape=(2,), dtype=int32, numpy=array([2, 3])>
tf.zeros([2,3]) #是接收shape, Out[17]: <tf.Tensor: id=141, shape=(2, 3), dtype=float32, numpy=array([[0., 0., 0.], [0., 0., 0.]], dtype=float32)>
tf.zeros_like
tf.zeros_like = tf.zeros(a.shape)
tf.ones & tf.ones_like
tf.ones_like = tf.ones(a.shape)
Fill
Normal & Truncated_Normal
normal 正態分佈, mean 均值(缺省是0), stddev 方差(缺省是1),
truncated_normal 截斷正態分佈, 截去 Gradient Vanish 梯度消失的部分。
Uniform
uniform 均勻分佈 minval 最小值, maxval 最大值
Random Permutation
Tf.random.shuffle: 隨機打散,洗牌。
Tf.gather: 根據指定的索引轉換對象。可以根據隨機打散後的索引取數據。
tf.constant
Tf.convert_to_tensor 與 tf.constant API基本一樣