zoukankan      html  css  js  c++  java
  • 吴裕雄--天生自然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])
  • 相关阅读:
    MAC使用小技巧(一)
    开发者:网站 & SDK
    编译 & 预处理
    归并排序 & 快速排序
    算法 & 分析 (收集)
    栈 & 堆 |--> 内存管理
    [ 单例、代理 & 通知 ]
    博客园:CSS & HTML
    比较、字符串
    Swift # 异常处理
  • 原文地址:https://www.cnblogs.com/tszr/p/12221514.html
Copyright © 2011-2022 走看看