tensorflow tf.softmax_cross_entropy相关问题

版权声明:任意转载 https://blog.csdn.net/Z609834342/article/details/84556297
output = tf.constant([1., 3., 2.])
output_ = tf.nn.softmax(output)
y = tf.constant([1., 3., 2.])


loss1 = tf.losses.softmax_cross_entropy(y, output)

loss2 = -tf.reduce_sum(y * tf.log(output_))
print(loss1)
print(loss2)

#tf.Tensor(6.4456363, shape=(), dtype=float32)
#tf.Tensor(6.4456363, shape=(), dtype=float32)

可以从上面简单的代码看出tf.softmax_cross_entropy是先将out进行类似softmax(为什么是类似知乎上有一定说明,但是这里实际调用的是softmax_cross_entropy_with_logits_v2(tf 1.9),跟softmax_cross_entropy_with_logits应该并无太大差别,这里没有深究)的操作,然后再进行cross entropy的操作。

问题:今天发现训练的模型train loss一直不动,发现是我的tf.losses.softmax_cross_entropy(y, output)两个参数写反。

猜你喜欢

转载自blog.csdn.net/Z609834342/article/details/84556297