tf.nn.sparse_softmax_cross_entropy_with_logits(y, tf.argmax(y_)):
y表示的是实际类别,y_表示预测结果,这实际上面是把原来的神经网络输出层的softmax和cross_entrop何在一起计算,为了追求速度。
例如:
复制代码
输出:
c2: [ 0.05403676]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20import tensorflow as tf; import numpy as np; import matplotlib.pyplot as plt; y2 = tf.convert_to_tensor([[0, 0, 1, 0]], dtype=tf.int64) y_2 = tf.convert_to_tensor([[-2.6, -1.7, 3.2, 0.1]], dtype=tf.float32) c2 = tf.nn.sparse_softmax_cross_entropy_with_logits(y_2, tf.argmax(y2, 1)) y3 = tf.convert_to_tensor([[0, 0, 1, 0], [0, 0, 1, 0]], dtype=tf.int64) y_3 = tf.convert_to_tensor([[-2.6, -1.7, -3.2, 0.1], [-2.6, -1.7, 3.2, 0.1]], dtype=tf.float32) c3 = tf.nn.sparse_softmax_cross_entropy_with_logits(y_3, tf.argmax(y3, 1)) y4 = tf.convert_to_tensor([[0, 1, 0, 0]], dtype=tf.int64) y_4 = tf.convert_to_tensor([[-2.6, -1.7, -3.2, 0.1]], dtype=tf.float32) c4 = tf.nn.sparse_softmax_cross_entropy_with_logits(y_4, tf.argmax(y4, 1)) with tf.Session() as sess: print 'c2: ' , sess.run(c2) print 'c3: ' , sess.run(c3) print 'c4: ' , sess.run(c4)
c3: [ 3.53853464 0.05403676]
c4: [ 2.03853464]
最后
以上就是稳重长颈鹿最近收集整理的关于tf.nn.sparse_softmax_cross_entropy_with_logits的用法的全部内容,更多相关tf.nn.sparse_softmax_cross_entropy_with_logits内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复