美文网首页
tf内置函数

tf内置函数

作者: Dorrrris | 来源:发表于2019-11-18 17:00 被阅读0次

reduce相关

除非写keep_dim,都会塌缩掉1个维度。某几个元素压缩成1个。
我看到过最好的介绍(关于reduce_sum):
http://hp.stuhome.net/index.php/2018/03/19/tensorflow-reduce_sum-meaning/
然后用https://www.jianshu.com/p/def3ce849bef做验证:

#axis=0:
[[[24 26]
  [28 30]
  [32 34]
  [36 38]]

 [[40 42]
  [44 46]
  [48 50]
  [52 54]]

 [[56 58]
  [60 62]
  [64 66]
  [68 70]]]
#axis=1
[[[ 24  27]
  [ 30  33]
  [ 36  39]
  [ 42  45]]

 [[ 96  99]
  [102 105]
  [108 111]
  [114 117]]]
#axis=2
[[[ 12  16]
  [ 44  48]
  [ 76  80]]

 [[108 112]
  [140 144]
  [172 176]]]
#axis=3
[[[ 1  5  9 13]
  [17 21 25 29]
  [33 37 41 45]]

 [[49 53 57 61]
  [65 69 73 77]
  [81 85 89 93]]]

tf.reduce_mean

就字面意思,计算平均值。

x = tf.constant([[1., 1.], [2., 2.]])
tf.reduce_mean(x)  # 1.5
tf.reduce_mean(x, 0)  # [1.5, 1.5]
tf.reduce_mean(x, 1)  # [1.,  2.]

关于axis

-1就是倒数第一维(最后一维),0是第一维……

关于initializer

https://www.cnblogs.com/denny402/p/6932956.html

xavier_initializer

如果激活函数使用sigmoid和tanh,则最好使用xavier。不大不小。

truncated_normal_initializer

它有四个参数(mean=0.0, stddev=1.0, seed=None, dtype=dtypes.float32),分别用于指定均值、标准差、随机数种子和随机数的数据类型,一般只需要设置stddev这一个参数就可以了。

相关文章

网友评论

      本文标题:tf内置函数

      本文链接:https://www.haomeiwen.com/subject/wbsbictx.html