TensorFlow 学习(十)—— 工具函数
1. 基本
tf.clip_by_value() 截断,常和对数函数结合使用
# 计算交叉熵 crose_ent = -tf.reduce_mean(tf.log(y_*tf.clip_by_value(y, 1e-10, 1.)))
a = tf.reshape(tf.range(6, dtype=tf.float32), [2, 3]) tf.clip_by_value(a, 2.5, 4.5) # 将值限定在 2.5 和 4.5 之间 array([[ 2.5, 2.5, 2.5], [ 3. , 4. , 4.5]], dtype=float32)
2. 条件分支:tf 下的三目运算符
tf.select(tf.greater(v1, v2), a*(v1-v2), a*(v2-v1))
当然上式也可化为:
声明:该文观点仅代表作者本人,牛骨文系教育信息发布平台,牛骨文仅提供信息存储空间服务。
- 上一篇: Tensorflow交叉熵计算错误
- 下一篇: TF-IDF及其算法