其他分享
首页 > 其他分享> > 吴裕雄--天生自然TensorFlow2教程:误差计算

吴裕雄--天生自然TensorFlow2教程:误差计算

作者:互联网

import tensorflow as tf

y = tf.constant([1, 2, 3, 0, 2])
y = tf.one_hot(y, depth=4)  # max_label=3种
y = tf.cast(y, dtype=tf.float32)

out = tf.random.normal([5, 4])
out
loss1 = tf.reduce_mean(tf.square(y - out))
loss1
loss2 = tf.square(tf.norm(y - out)) / (5 * 4)
loss2
loss3 = tf.reduce_mean(tf.losses.MSE(y, out))
loss3

a = tf.fill([4], 0.25)
a * tf.math.log(a) / tf.math.log(2.)
-tf.reduce_sum(a * tf.math.log(a) / tf.math.log(2.))
a = tf.constant([0.1, 0.1, 0.1, 0.7])
-tf.reduce_sum(a * tf.math.log(a) / tf.math.log(2.))
a = tf.constant([0.01, 0.01, 0.01, 0.97])
-tf.reduce_sum(a * tf.math.log(a) / tf.math.log(2.))

 

 

 

 

 

 

 

 

tf.losses.categorical_crossentropy([0, 1, 0, 0], [0.25, 0.25, 0.25, 0.25])
tf.losses.categorical_crossentropy([0, 1, 0, 0], [0.1, 0.1, 0.8, 0.1])
tf.losses.categorical_crossentropy([0, 1, 0, 0], [0.1, 0.7, 0.1, 0.1])
tf.losses.categorical_crossentropy([0, 1, 0, 0], [0.01, 0.97, 0.01, 0.01])
tf.losses.BinaryCrossentropy()([1],[0.1])
tf.losses.binary_crossentropy([1],[0.1])

标签:TensorFlow2,教程,0.01,log,0.1,losses,tf,吴裕雄,math
来源: https://www.cnblogs.com/tszr/p/12221514.html