1.指数衰减函数的参数和计算方程:
tensorflow提供了一个灵活的学习率设置方法,指数衰减函数tf.train.exponential_decay(),它的计算实现如下: decayed_learning_rate = learning_rate * decay_rate ^ (global_step / decay_steps)
其中decay_rate是衰减系数(取值小于1,比如0.1), global_steps是当前迭代次数,decay_steps是总的迭代次数,learning_rate是初始学习率。
2. onehot=True
在多类场景下,onehot=true表示,只有一个元素的值是1,其他元素的值是0, 一个长度为n的数组,只有一个元素是1.0,其他元素是0.0。
onehot=False则没有这样的限制。
3. Tensorflow交叉熵函数:cross_entropy
计算公式: pos_weight*labels * -log(sigmoid(logits)) + (1 - labels) * -log(1 - sigmoid(logits))
sparse_softmax_cross_entropy_with_logits and softmax_cross_entropy_with_logits的区别:
Having two different functions is a convenience, as they produce the same result.
The difference is simple:
- For
sparse_softmax_cross_entropy_with_logits
, labels must have the shape [batch_size] and the dtype int32 or int64. Each label is an int in range[0, num_classes-1]
. - For
softmax_cross_entropy_with_logits
, labels must have the shape [batch_size, num_classes] and dtype float32 or float64.
Labels used in softmax_cross_entropy_with_logits
are the one hot version of labels used in sparse_softmax_cross_entropy_with_logits
.
Another tiny difference is that with sparse_softmax_cross_entropy_with_logits
, you can give -1 as a label to have loss 0
on this label.
看下图就明白了
答案就是上面那个 gradients!!!
这张图里面 gradients 看上去只是小小的一个框,代码里面也只有 tf.train.GradientDescentOptimizer() 这么一句,但是如果我们把这个框展开。