标签: generative-adversarial-network

GAN 的损失函数的理想值是多少

最初由 IJ Goodfellow 提出的 GAN 使用以下损失函数,

D_loss = - log[D(X)] - log[1 - D(G(Z))]

G_loss = - log[D(G(Z))]
Run Code Online (Sandbox Code Playgroud)

因此,鉴别器尝试最小化 D_loss,生成器尝试最小化 G_loss,其中 X 和 Z 分别是训练输入和噪声输入。D(.) 和 G(.) 分别是鉴别器和生成器神经网络的映射。

正如原始论文所说,当 GAN 被训练几个步骤时,它会达到一个生成器和判别器都无法改进的点,并且 D(Y) 到处都是 0.5,Y 是判别器的一些输入。在这种情况下,当 GAN 被充分训练到这一点时,

D_loss = - log(0.5) - log(1 - 0.5) = 0.693 + 0.693 = 1.386

G_loss = - log(0.5) = 0.693
Run Code Online (Sandbox Code Playgroud)

那么,为什么我们不能使用 D_loss 和 G_loss 值作为评估 GAN 的指标呢?

如果两个损失函数偏离了这些理想值,那么 GAN 肯定需要训练好或架构需要设计好。正如原始论文中的定理 1 所讨论的,这些是 D_loss 和 G_loss 的最佳值,但为什么不能将它们用作评估指标?

loss neural-network objective-function generative-adversarial-network

5
推荐指数
1
解决办法
3956
查看次数

用于域翻译的条件 GAN

我正在训练一个 GAN 从两个不同的图像域(源S和目标T)执行样式转换。因为我有可用的类信息,所以我有一个额外的Q网络(除了GD),它测量目标域及其标签(LeNet 网络)的生成图像的分类结果,并将错误传播到生成器以及D. 从系统的收敛性我注意到它D总是从 8(网络的损失函数误差D)开始并略微下降到 4.5,并且G损失函数误差从 1 开始并迅速下降到 0.2。的损失函数DG我使用的,可以发现在这里,而丧失功能Q网络是分类交叉熵。迭代中的误差图是:

在此处输入图片说明

D和G的损失函数为:

def discriminator_loss(y_true,y_pred):
      BATCH_SIZE=10
      return K.mean(K.binary_crossentropy(K.flatten(y_pred), K.concatenate([K.ones_like(K.flatten(y_pred[:BATCH_SIZE,:,:,:])),K.zeros_like(K.flatten(y_pred[:BATCH_SIZE,:,:,:])) ]) ), axis=-1)

def discriminator_on_generator_loss(y_true,y_pred):
     BATCH_SIZE=10
     return K.mean(K.binary_crossentropy(K.flatten(y_pred), K.ones_like(K.flatten(y_pred))), axis=-1)

def generator_l1_loss(y_true,y_pred):
     BATCH_SIZE=10
     return K.mean(K.abs(K.flatten(y_pred) - K.flatten(y_true)), axis=-1)
Run Code Online (Sandbox Code Playgroud)

D 的误差函数总是那么高有意义吗?什么是错误的解释DG?是不是开始时的损失D应该很小,迭代后会上升?用损失阈值限制D过度是个好主意G吗?最后,在训练期间计算来自验证集的损失函数而不是我正在使用的训练集的误差是否有意义?(而不是直接使用 train_on_batch 使用 fit 然后在测试集上进行评估)。

编辑:

对于损失,我认为损失discriminator …

python keras generative-adversarial-network

5
推荐指数
1
解决办法
325
查看次数

我不断收到 StyleGAN 的断言错误

最近我一直在玩 StyleGAN 并生成了一个数据集,但是当我尝试运行 train.py 时得到以下信息。

2020-01-08 13:33:21.943217: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudart64_100.dll
WARNING:tensorflow:From C:\Users\MyName\Desktop\StyleGan\stylegan-master\dnnlib\tflib\tfutil.py:34: The name tf.Dimension is deprecated. Please use tf.compat.v1.Dimension instead.

WARNING:tensorflow:From C:\Users\MyName\Desktop\StyleGan\stylegan-master\dnnlib\tflib\tfutil.py:74: The name tf.variable_scope is deprecated. Please use tf.compat.v1.variable_scope instead.

WARNING:tensorflow:From C:\Users\MyName\Desktop\StyleGan\stylegan-master\dnnlib\tflib\tfutil.py:128: The name tf.Session is deprecated. Please use tf.compat.v1.Session instead.

Creating the run dir: results\00003-sgan-datasets-1gpu
Copying files to the run dir
dnnlib: Running training.training_loop.training_loop() on localhost...
WARNING:tensorflow:From C:\Users\MyName\Desktop\StyleGan\stylegan-master\dnnlib\tflib\tfutil.py:97: The name tf.get_default_session is deprecated. Please use tf.compat.v1.get_default_session instead.

WARNING:tensorflow:From C:\Users\MyName\Desktop\StyleGan\stylegan-master\dnnlib\tflib\tfutil.py:109: The name tf.set_random_seed is …
Run Code Online (Sandbox Code Playgroud)

python deep-learning tensorflow generative-adversarial-network

5
推荐指数
1
解决办法
1961
查看次数

如何限制 LSTM 模型中的序列预测以匹配特定模式?

我使用 LSTM 模型创建了一个词级文本生成器。但就我而言,并非每个词都适合选择。我希望它们匹配其他条件:

  1. 每个单词都有一个映射:如果一个字符是元音,那么它会写 1,否则会写 0(例如,溢出10100010)。然后,生成的句子需要满足给定的结构,例如,01001100hi 01朋友 001100)。
  2. 最后一个单词的最后一个元音必须是提供的那个。假设是e。(周五ê将做的工作,然后)。

因此,为了处理这种情况,我创建了一个具有以下结构的 Pandas 数据框:

word    last_vowel  word_map
-----   ---------   ----------
hello   o           01001
stack   a           00100
jhon    o           0010
Run Code Online (Sandbox Code Playgroud)

这是我目前的工作流程:

  1. 给定句子结构,我从数据框中选择一个与模式匹配的随机单词。例如,如果句子结构是0100100100100,我们可以选择单词hello,因为它的元音结构是01001
  2. 我从剩余的结构中减去选定的单词:0100100100100will be become00100100因为我们已经删除了首字母01001( hello )。
  3. 我从与剩余结构的一部分匹配的数据帧中检索所有单词,在本例中为stack 00100jhon 0010
  4. 我将当前单词句子内容(现在只是hello)传递给 LSTM 模型,它检索每个单词的权重。
  5. 但我不只是想选择最佳选项,我想选择第 3 点选择中包含的最佳选项。所以我选择了该列表中估计值最高的单词,在本例中为stack
  6. 从第 …

machine-learning reinforcement-learning fst lstm generative-adversarial-network

5
推荐指数
1
解决办法
140
查看次数

为什么有些人将两个不同网络的参数链接起来并使用相同的优化器进行训练?

我正在查看 CycleGAN 的官方 pytorch 实现,作者在那里链接了两个网络的参数,并为两个网络使用了一个优化器。这是如何运作的?是否比对两个不同的网络使用两个不同的优化器更好?

all_params = chain(module_a.parameters(), module_b.parameters())
optimizer = torch.optim.Adam(all_params)
Run Code Online (Sandbox Code Playgroud)

python deep-learning pytorch generative-adversarial-network

5
推荐指数
1
解决办法
475
查看次数

如何使用 tf.strategy 修改 Keras CycleGAN 示例代码以在 GPU 上并行运行

以下是使用 Keras 的 Keras CycleGAN 示例中的 CycleGAN 示例

这是我修改后的使用多个 GPU 的实现。为了实现自定义训练,我使用了带有 tf.distribute.Strategy 的参考自定义训练

我想要一个来自 Keras 的 CycleGAN 示例,以便使用 GPU 快速运行。此外,我需要处理和训练大量数据。CycleGAN 使用多个损失函数train_step会返回 4 种损失,目前我只返回一种以便于理解。尽管如此,GPU 上的训练还是非常慢。我无法找到这背后的原因。

难道是我用tf.distribute.Strategy错了?

"""
Title: CycleGAN
Author: [A_K_Nain](https://twitter.com/A_K_Nain)
Date created: 2020/08/12
Last modified: 2020/08/12
Description: Implementation of CycleGAN.
"""

"""
## CycleGAN
CycleGAN is a model that aims to solve the image-to-image translation
problem. The goal of the image-to-image translation problem is to learn the
mapping between an input image and an …
Run Code Online (Sandbox Code Playgroud)

parallel-processing multi-gpu keras tensorflow generative-adversarial-network

5
推荐指数
0
解决办法
610
查看次数

如何微调预训练的 GAN?

我想使用我自己的图像对在线提供的预训练 GAN 进行微调。例如,在 ImageNet 上训练的 BigGAN 可以生成逼真的图像。但是,我不想在 ImageNet 中生成图像类。我想生成我自己的图像集的人工图像。如何微调预训练模型?它与微调其他神经网络(如 CNN 图像分类模型)相同吗?仅替换/重新训练最后几层就足够了吗?如果我能在 Tensorflow/Keras 代码中看到一些示例,那就太好了。非常感谢!

BigGAN https://tfhub.dev/deepmind/biggan-deep-256/1

deep-learning tensorflow tensorflow-hub transfer-learning generative-adversarial-network

5
推荐指数
1
解决办法
2607
查看次数

我如何使用 tensorflow 2 进行均衡学习率?

我正在尝试使用 tensorflow 版本 2 实现 StyleGAN,但我不知道如何进行均衡学习率。我尝试用这种方式缩放渐变:

等级均衡

但它不能正常工作。

请帮忙。

python tensorflow generative-adversarial-network

4
推荐指数
1
解决办法
451
查看次数

启用急切执行时不支持 Keras 优化器

我正在尝试生成 mnist 数据集图像。这是我的代码:

fns.py:

import math
import numpy as np

def combine_images(generated_images):
    total,width,height = generated_images.shape[:-1]
    cols = int(math.sqrt(total))
    rows = math.ceil(float(total)/cols)
    combined_image = np.zeros((height*rows, width*cols),
                              dtype=generated_images.dtype)

    for index, image in enumerate(generated_images):
        i = int(index/cols)
        j = index % cols
        combined_image[width*i:width*(i+1), height*j:height*(j+1)] = image[:, :, 0]
    return combined_image

def show_progress(epoch, batch, g_loss, d_loss, g_acc, d_acc):
    msg = "epoch: {}, batch: {}, g_loss: {}, d_loss: {}, g_accuracy: {}, d_accuracy: {}"
    print(msg.format(epoch, batch, g_loss, d_loss, g_acc, d_acc))
Run Code Online (Sandbox Code Playgroud)

主要.py:

from tensorflow.python.keras.models import Sequential
from …
Run Code Online (Sandbox Code Playgroud)

keras tensorflow generative-adversarial-network

4
推荐指数
1
解决办法
9341
查看次数

无法将 cuda:0 设备类型张量转换为 numpy。首先使用 Tensor.cpu() 将张量复制到主机内存

我试图展示 GAN 网络在某些指定时期的结果。打印当前结果的功能之前是在 TF 中使用的。我需要换成pytorch。

def show_result(G_net, z_, num_epoch, show=False, save=False, path='result.png'):


  #test_images = sess.run(G_z, {z: z_, drop_out: 0.0})
  test_images = G_net(z_)

  size_figure_grid = 5
  fig, ax = plt.subplots(size_figure_grid, size_figure_grid, figsize=(5, 5))

  for i, j in itertools.product(range(size_figure_grid), range(size_figure_grid)):
     ax[i, j].get_xaxis().set_visible(False)
     ax[i, j].get_yaxis().set_visible(False)

  for k in range(5*5):
     i = k // 5
     j = k % 5
     ax[i, j].cla()
     ax[i, j].imshow(np.reshape(test_images[k], (28, 28)), cmap='gray')

  label = 'Epoch {0}'.format(num_epoch)
  fig.text(0.5, 0.04, label, ha='center')

  plt.savefig(name)
  file = drive.CreateFile({'title': label, "parents": [{"kind": "https://drive.google.com/drive/u/0/folders/", "id": …
Run Code Online (Sandbox Code Playgroud)

python plot pytorch generative-adversarial-network

3
推荐指数
1
解决办法
1万
查看次数