在哪里使用二进制二进制交叉熵损失
Where to use binary Binary Cross-Entropy Loss
我有两个问题:
是否有任何来源可以让我看到 TensorFlow 对这些损失函数的实现?我在他们的网站上 Github 上搜索过,但没有找到实现这些损失函数所依据的公式。
当我使用tf.keras.losses.BinaryCrossentropy(from_logits=True)时,损失函数应该是什么目标?一个热向量([[0,1]])还是常数张量([1])?我观察并注意到它对它们都有效。你能写下公式吗?
编辑:我有分类,比如猫和狗。
- 您应该查看官方 Tensorflow API 文档:https://www.tensorflow.org/api_docs/python/tf/keras/losses/binary_crossentropy. At the top of the page you can find a link "View source on GitHub". This loss refers to the Keras backend implementation to binary crossentropy: https://github.com/tensorflow/tensorflow/blob/b36436b087bd8e8701ef51718179037cccdfc26e/tensorflow/python/keras/backend.py#L4795
- 也来自文档:“当只有两个标签 类(假设为 0 和 1)时使用此 cross-entropy 损失。对于每个示例,应该每个预测是一个 floating-point 值。"
y_true
和 y_pred
应该是这样的张量:
import tensorflow as tf
binary_crossentropy = tf.keras.losses.BinaryCrossentropy()
a = tf.convert_to_tensor([1., 1., 0., 1., 0., 0.])
b = tf.convert_to_tensor([.1, .9, 2., 8., 4., 3.])
binary_crossentropy(a, b)
<tf.Tensor: shape=(), dtype=float32, numpy=8.067944>
如果最后一层没有激活函数,from_logits
应该是 True
。如果机器人是 one-hot 编码,它也可以工作:
d = tf.convert_to_tensor([[.4, .6], [.8, .2], [.7, .3], [.1, .9], [.2, .8], [.4, .6]])
c = tf.convert_to_tensor([[.8, .2], [.3, .7], [.4, .6], [.9, .1], [.2, .8], [.7, .3]])
binary_crossentropy(c, d)
<tf.Tensor: shape=(), dtype=float32, numpy=1.0452858>
我有两个问题:
是否有任何来源可以让我看到 TensorFlow 对这些损失函数的实现?我在他们的网站上 Github 上搜索过,但没有找到实现这些损失函数所依据的公式。
当我使用tf.keras.losses.BinaryCrossentropy(from_logits=True)时,损失函数应该是什么目标?一个热向量([[0,1]])还是常数张量([1])?我观察并注意到它对它们都有效。你能写下公式吗?
编辑:我有分类,比如猫和狗。
- 您应该查看官方 Tensorflow API 文档:https://www.tensorflow.org/api_docs/python/tf/keras/losses/binary_crossentropy. At the top of the page you can find a link "View source on GitHub". This loss refers to the Keras backend implementation to binary crossentropy: https://github.com/tensorflow/tensorflow/blob/b36436b087bd8e8701ef51718179037cccdfc26e/tensorflow/python/keras/backend.py#L4795
- 也来自文档:“当只有两个标签 类(假设为 0 和 1)时使用此 cross-entropy 损失。对于每个示例,应该每个预测是一个 floating-point 值。"
y_true
和 y_pred
应该是这样的张量:
import tensorflow as tf
binary_crossentropy = tf.keras.losses.BinaryCrossentropy()
a = tf.convert_to_tensor([1., 1., 0., 1., 0., 0.])
b = tf.convert_to_tensor([.1, .9, 2., 8., 4., 3.])
binary_crossentropy(a, b)
<tf.Tensor: shape=(), dtype=float32, numpy=8.067944>
如果最后一层没有激活函数,from_logits
应该是 True
。如果机器人是 one-hot 编码,它也可以工作:
d = tf.convert_to_tensor([[.4, .6], [.8, .2], [.7, .3], [.1, .9], [.2, .8], [.4, .6]])
c = tf.convert_to_tensor([[.8, .2], [.3, .7], [.4, .6], [.9, .1], [.2, .8], [.7, .3]])
binary_crossentropy(c, d)
<tf.Tensor: shape=(), dtype=float32, numpy=1.0452858>