TensorFlow函数-02
1、tf.distributions.Normal()
该函数定义了一个正态分布。
tfp.distributions.Normal( loc, scale, validate_args=False, allow_nan_stats=True, name=‘Normal’)
loc:均值
scale:标准差
比如:tf.distributions.Normal(loc=0,scale=1) # 这个是标准正态分布
2、log_prob(value)
用来计算value在定义的正态分布(mean,1)中对应的概率的对数。
参考链接:log_prob(value)
3、tf.stop_gradient(input,name=None)
用stop_gradient生成损失函数的梯度。
函数参数:
input:A Tensor.
name:操作的名称(可选).
函数返回值:
一Tensor,与input类型相同.
4、tf.clip_by_value(A, min, max)
输入一个张量A,把A中的每一个元素的值都压缩在min和max之间。小于min的让它等于min,大于max的元素的值等于max。
5、tf.squeeze(input,axis=None,name=None)
从张量形状中移除大小为1的维度.
给定一个张量 input,该操作返回一个与已经移除的所有大小为1的维度具有相同类型的张量.如果您不想删除所有大小为1的维度,则可以通过指定 axis 来删除特定的大小为1的维度.
# 't' is a tensor of shape [1, 2, 1, 3, 1, 1]
tf.shape(tf.squeeze(t, [2, 4])) # [1, 2, 3, 1]
6、tensorflow 中names_cope 与variable_scope的区别
使用tf.Variable()的时候,tf.name_scope()和tf.variable_scope() 都会给 Variable 和 op 的 name属性加上前缀。
使用tf.get_variable()的时候,tf.name_scope()就不会给 tf.get_variable()创建出来的Variable加前缀。但是tf.variable_scope()会给 tf.get_variable()创建出来的Variable加前缀。