DCGANs:鉴别器变得过于强大,过快,无法让生成器学习

2024-04-29 09:35:42 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试对一些数据使用this version of the DCGAN code(在Tensorflow中实现)。我遇到了一个问题,鉴别器变得太强,太快,发电机无法学习任何东西。

现在有一些技巧通常被推荐用于解决GANs的问题:

  • 批量标准化(在DCGANs代码中已经存在)

  • 启动发电机。

我做了后者的一些版本,每1个鉴别器允许10次生成器迭代(不仅在开始时,而且在整个培训过程中),这就是它的外观: Loss functions of generator and discriminator

<> P>在这种情况下添加更多的发电机迭代只会减慢不可避免的鉴别器增长太强和抑制生成器学习。

因此,我想就是否有其他方法可以帮助解决一个太强的歧视者的问题征求意见?


Tags: ofthe数据代码版本技巧versiontensorflow
2条回答

总结本主题-一般建议如下:

  • 尝试使用模型参数(例如,学习率)
  • 尝试向输入数据添加更多种类
  • 尝试调整生成器和鉴别器的结构 网络。

但是,在我的例子中,问题是数据缩放:我已经将输入数据的格式从initial.jpg更改为.npy,并且在途中丢失了重缩放。请注意this DCGAN-tensorflow code将输入数据重新调整为[-1,1]范围,并且模型已调整为使用此范围。

我认为有几种方法可以减少鉴别器:

  1. 在鉴别器功能中尝试漏泄和退出:

    def leaky_relu(x, alpha, name="leaky_relu"): return tf.maximum(x, alpha * x , name=name)

以下是整个定义:

def discriminator(images, reuse=False):

# Implement a seperate leaky_relu function
def leaky_relu(x, alpha, name="leaky_relu"):
    return tf.maximum(x, alpha * x , name=name)

# Leaky parameter Alpha 
alpha = 0.2

# Add batch normalization, kernel initializer, the LeakyRelu activation function, ect. to the layers accordingly
with tf.variable_scope('discriminator', reuse=reuse):
    # 1st conv with Xavier weight initialization to break symmetry, and in turn, help converge faster and prevent local minima.
    images = tf.layers.conv2d(images, 64, 5, strides=2, padding="same", kernel_initializer=tf.contrib.layers.xavier_initializer())
    # batch normalization
    bn = tf.layers.batch_normalization(images, training=True)
    # Leaky relu activation function
    relu = leaky_relu(bn, alpha, name="leaky_relu")
    # Dropout "rate=0.1" would drop out 10% of input units, oppsite with keep_prob
    drop = tf.layers.dropout(relu, rate=0.2)

    # 2nd conv with Xavier weight initialization, 128 filters.
    images = tf.layers.conv2d(drop, 128, 5, strides=2, padding="same", kernel_initializer=tf.contrib.layers.xavier_initializer())
    bn = tf.layers.batch_normalization(images, training=True)
    relu = leaky_relu(bn, alpha, name="leaky_relu")
    drop = tf.layers.dropout(relu, rate=0.2)

    # 3rd conv with Xavier weight initialization, 256 filters, strides=1 without reshape
    images = tf.layers.conv2d(drop, 256, 5, strides=1, padding="same", kernel_initializer=tf.contrib.layers.xavier_initializer())
    #print(images)
    bn = tf.layers.batch_normalization(images, training=True)
    relu = leaky_relu(bn, alpha, name="leaky_relu")
    drop = tf.layers.dropout(relu, rate=0.2)


    flatten = tf.reshape(drop, (-1, 7 * 7 * 128))
    logits = tf.layers.dense(flatten, 1)
    ouput = tf.sigmoid(logits)  

    return ouput, logits
  1. 在鉴别器丢失中添加标签平滑以防止鉴别器变强。根据损耗性能增加平滑值。

    d_loss_real = tf.reduce_mean( tf.nn.sigmoid_cross_entropy_with_logits(logits=d_logits_real, labels=tf.ones_like(d_model_real)*(1.0 - smooth)))

相关问题 更多 >