TensorFlow Basics (three) - tf.nn.softmax_cross_entropy_with_logits

tf.nn.softmax_cross_entropy_with_logits () function is a function to calculate the cross-entropy TensorFlow common.

Subsequent versions, TensorFlow update: tf.nn.softmax_cross_entropy_with_logits_v2


The format is:

cross_entropy = tf.nn.softmax_cross_entropy_with_logits(labels=y_, logits=y )


Parameter Description:

labels: classification label
logits: the predicted value



TensorFlow code implements tf.nn.softmax_cross_entropy_with_logits () function:

import tensorflow as tf
 
labels = [[0.1, 0.2, 0.6],
          [0.4, 0.9, 0.7]]
logits = [[1, 2, 4],
          [0.1, -1, 3]]
 
# 计算交叉熵(tf.nn.softmax_cross_entropy_with_logits更新为格
# tf.nn.softmax_cross_entropy_with_logits_v2)
cross_entropy = tf.nn.softmax_cross_entropy_with_logits_v2(labels=labels, logits=logits)
 
with tf.Session() as sess:
    print(sess.run(cross_entropy))


operation result:

[0.85286146 4.9015484 ]


 

Published 352 original articles · won praise 115 · views 130 000 +

Guess you like

Origin blog.csdn.net/Aidam_Bo/article/details/103189770