【问题标题】:Can't understand the loss functions for the GAN model used in the tensorflow documentation无法理解 tensorflow 文档中使用的 GAN 模型的损失函数
【发布时间】:2020-08-12 18:31:29
【问题描述】:

我无法理解 TensorFlow 文档中 GAN 模型中的损失函数。为什么将tf.ones_like() 用于real_losstf.zeros_like() 用于假输出??

def discriminator_loss(real_output,fake_output):
  real_loss = cross_entropy(tf.ones_like(real_output),real_output)
  fake_loss = cross_entropy(tf.zeros_like(fake_output),fake_output)
  total_loss = real_loss + fake_loss
  return total_loss

【问题讨论】:

    标签: machine-learning deep-learning tensorflow2.0 generative-adversarial-network


    【解决方案1】:

    我们有以下损失函数,我们需要以最小最大方式(或最小最大,如果你想这样称呼它)最小化。

    1. generator_loss = -log(generated_labels)
    2. discriminator_loss = -log(real_labels) - log(1 - generated_labels)

    其中real_output = real_labels 和fake_output = generated_labels。

    现在,考虑到这一点,让我们看看 TensorFlow 文档中的代码 sn-p 代表什么:

    • real_loss = cross_entropy(tf.ones_like(real_output), real_output) 评估为
      • real_loss = -1 * log(real_output) - (1 - 1) * log(1 - real_output) = -log(real_output)
    • fake_loss = cross_entropy(tf.zeros_like(fake_output),fake_output) 评估为
      • fake_loss = -0 * log(fake_output) - (1 - 0) * log(1 - fake_output) = -log(1 - fake_output)
    • total_loss = real_loss + fake_loss 评估为
      • total_loss = -log(real_output) - log(1 - fake_output)

    显然,我们得到了我们想要最小化的 mini-max 游戏中判别器的损失函数。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-08-26
      • 2018-10-03
      • 2021-11-19
      • 2018-03-14
      • 1970-01-01
      • 2018-06-02
      • 1970-01-01
      • 2019-01-20
      相关资源
      最近更新 更多