import tensorflow as tf
logits = tf.constant([[4.0, 2.0, 3.0], [1.0, 3.0, 5.0], [1.0, 2.0, 3.0]])
y_ = tf.constant([[0.0, 0.5, 1.0], [0.0, 0.0, 1.0], [0.0, 0.0, 1.0]])
def cross():
y = tf.nn.softmax(logits)
cross_entropy = tf.reduce_mean(tf.reduce_sum(-y_ * tf.log(y),1))
cross_entropy2 = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(logits=logits,labels=y_))
with tf.Session() as sess:
result = sess.run(y)
print(result)
c_e = sess.run(cross_entropy)
c_e2 = sess.run(cross_entropy2)
print("my cross_entropy result=")
print(c_e)
print("Function(softmax_cross_entropy_with_logits) result=")
print(c_e2)
cross()