吴裕雄--天生自然TensorFlow2教程:误差计算
2024-09-05 20:50:46
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])
最新文章
- 把普通对象转换成json格式的对象
- git乱码问题解决
- python-appium识别元素等待时间
- vs2012 MSDN帮助文档离线包下载安装方法
- diff和common
- CentOS 的网络配置
- Codeforces Round #189 (Div. 1) B. Psychos in a Line 单调队列
- JAVA将Excel中的报表导出为图片格式(一)问题背景
- 你不需要jQuery(四)
- BoundsChecker使用
- HDU 3480 DP+斜率优化
- 解决Android Device Chooser 找不到设备问题
- iOS制作毛玻璃效果
- 获取token之后,再调用匿名方法
- spring-session 共享
- IDEA配合Flash CS6开发Flash项目--配置篇
- Python12/11--盒子的显隐/布局/z-index/流式布局思想
- css组合选择器
- 清除win下连接的linux的samba服务缓存 用户名和密码
- Zookeeper 配置集群环境详解